2017-04-23 78 views
0

我想這傳遞到從前端的職位,但我不斷收到這條線上這個錯誤,我想不通這是爲什麼字符串的索引必須是整數,而不是str的 - Django的

{"isUpdated": true}通過這

在我的Django

,我有這些

body_unicode = request.body.decode('utf-8') 
    data = json.loads(body_unicode) 

    if data['isUpdated'] is not False: 
    # more codes 

我一直對這個if data['isUpdated'] is not False:

能有人給我SUG得到錯誤gestions發生了什麼?

+0

也許它會將「true」編碼爲str。檢查數據的值和數據的類型['isUpdated']' – Algorithmatic

+0

解析這些數據之前'body_unicode'的值是多少? –

+0

@算法值爲True,類型爲bol – Tsuna

回答

0

string indices must be integers, not str錯誤意味着data變量包含字符串,和Python抱怨並不能使用字符串來訪問包含在該字符串中的字符(data[0]將返回的第一個字符,將返回第二個字符等on,但data['isUpdated']會返回什麼?)

請求正文包含什麼內容?只是文章的文本或JSON對象?

相關問題