Moim zdaniem próbuję pętli wszystkie strony i wyodrębnić nazwę dla każdego przy użyciu poniższego kodu, ale wydaje się, że nie działa.
Jak mogę to osiągnąć?
view.py
json_dict = json.loads(request.POST["site"])
for item in json_dict["pages"]:
item.json_dict["name"]
dane JSON
{
"someitem": "xaAX",
"pages": [
{
"id": "1364484811734",
"name": "Page Name",
"type": "basic",
"components": {
"img": "",
"text": ""
}
},
{
"id": "1364484812918",
"name": "Contact",
"type": "contact",
"components": {
"text": "Send us an email using the form below.",
"contact-form": {
"contact-name": "zzz",
"contact-email": "zz"
}
}
},
]
}
Odpowiedzi:
1 dla odpowiedzi № 1To powinno działać:
json_dict = json.loads(request.POST["site"])
for item in json_dict["pages"]:
print item["name"]