如何使用request.body读取数据JSON

时间:2015-05-31 00:40:03

标签: jquery python json django-views

我从jquery收到json:

dataJSON = urllib.unquote(request.body.decode("utf-8"))
print dataJSON
horarios=[{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0},{"horario":"6_20_23","estado":0}]

我尝试用for:

读取数据
for key in dataJSON:
    print key

enter image description here

2 个答案:

答案 0 :(得分:1)

import json

dataJSON = json.loads(request.body.decode("utf-8"))

for key in dataJSON:
    print key

我不确定您是否需要urllib.unquotedataJSON = json.loads(urllib.unquote(request.body.decode("utf-8"))),请尝试两者并查看

答案 1 :(得分:0)

解决了以下问题:

dataJSON2 = []
dataJSON = urllib.unquote(request.body.decode("utf-8"))
dataJSON2 = dataJSON[9:]
dataJSON2 = json.loads(dataJSON2)
for key in dataJSON2:
    print key['horario']