你好我試圖解析JSON陣列從安卓 從機器人的外觀發送類似解析JSON數組
[{"record":[{"intensity":"Low","body_subpart":"Scalp","symptom":"Agitation"}]}]
JSON響應發送的Django現在我的Django的功能如下:
record = simplejson.loads(request.POST['record'])
for o in record:
new_symptoms=UserSymptoms(health_record=new_healthrecord,body_subpart=o.body_subpart,symptoms=o.symptom,intensity=o.intensity)
new_symptoms.save()
,但它不工作 gving我的錯誤 對於我也嘗試執行上面的python外殼線條
>>>rec=json.loads('[{"intensity":"Low","body_subpart":"Scalp","symptom":"Agitation"},{"intensity":"High","body_subpart":"Scalp","symptom":"Bleeding"}]')
>>> for o in rec:
... print rec.body_subpart
...
Traceback (most recent call last):
File "<console>", line 2, in <module>
AttributeError: 'list' object has no attribute 'body_subpart'
爲什麼'rec.body_subpart'而不是'o.body_subpart'? – San4ez 2012-04-08 08:26:37
抱歉打字錯誤其o.body_subpart – user1163236 2012-04-08 08:47:07