如何访问json值,数据结构是字典中的字典列表,带有javascript循环

时间:2016-11-21 11:53:20

标签: javascript json dictionary

我有以下json结构:

 [
   {
      "model":"todolist.todolist",
      "pk":1,
      "fields":{
         "timezoneChoice":"Africa/Johannesburg",
         "user":44,
         "name":"ergdsg",
         "discription":"dsgdsg",
         "dueMinutes":-61504892,
         "emailSent":false,
         "dueDate":"1899-12-11T08:20:00Z",
         "create_at":"2016-11-21T04:37:29.253Z"
      }
   },
   {
      "model":"todolist.todolist",
      "pk":2,
      "fields":{
         "timezoneChoice":"Africa/Johannesburg",
         "user":44,
         "name":"ergdsg",
         "discription":"dsgdsg",
         "dueMinutes":-61504892,
         "emailSent":false,
         "dueDate":"1899-12-11T08:20:00Z",
         "create_at":"2016-11-21T04:38:12.525Z"
      }
   }
]

我需要得到像这样的值

for (var i = 0; i < json.length; i++) {

                    $("#posts").prepend( "<div >" +"<h2 class='bg-info   text-align-center'> Tasks" +"</h2>"
                                         + "<strong> Name: " + " "  + json[i].name + "</strong>"
                                         + "<strong> Task: " + " "  + json[i].discription + "</strong>"
                                         + "<strong> Due Date: " + " "  + json[i].dueDate + "</strong>"
                                         + "<strong> Mins before due: " + " "  + json[i].dueMinutes + "</strong>"
                                         + "<strong> TimeZone: " + " "  + json[i].timezoneChoice + "</strong>"
                                         + "<hr>" +"</div>")
                                },

如何循环浏览json以获取“fields”键字典,然后访问其中的键和值。我如何为整个杰森名单做这个?

谢谢

0 个答案:

没有答案