2013-03-28 5 views
0

제 생각에는 모든 페이지를 반복하고 아래 코드를 사용하여 각각의 이름을 추출하려고합니다. 그러나 작동하지 않는 것 같습니다.Django AJAX 루핑 데이터

내가 어떻게 이것을 달성 할 수 있습니까?

view.py

json_dict = json.loads(request.POST['site']) 


    for item in json_dict['pages']: 

      item.json_dict['name'] 

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" 
       } 
      } 
     }, 

    ] 
} 

답변

1

이 작동합니다 :

json_dict = json.loads(request.POST['site']) 

for item in json_dict['pages']: 
    print item['name']