我如何迭代json对象

时间:2016-06-30 18:04:32

标签: json

这个json formate基本上有两个数组对象,所以我有点困惑,我如何迭代这两个对象并分别显示。

[
   {
      "todays_birthday":[
         {
            "member_id":"1",
            "member_name":"Subhash Chander Chandna",
            "member_number":"490",
            "member_dob":"1995-06-30"
         },
         {
            "member_id":"4",
            "member_name":"Mrs. Bimla Rani",
            "member_number":"500",
            "member_dob":"1946-06-30"
         }
      ]
   },
   {
      "tommorow_birthday":[
         {
            "member_id":"3",
            "member_name":"Jagdish Kumar Pahuja",
            "member_number":"490",
            "member_dob":"1946-07-01"
         },
         {
            "member_id":"5",
            "member_name":"Raja Ram",
            "member_number":"500",
            "member_dob":"1946-07-01"
         }
      ]
   }
]

1 个答案:

答案 0 :(得分:0)

我认为您的json可以形成为具有两个属性(today_birthdaystomorrow_birthdays)的对象,并且在每个属性中都可以获得生日数组。

就像那样:

{
  today_birthdays: [
    //birthdays
  ],
  tomorrow_birthdays: [
    //birthdays
  ]
}

因此您可以使用lodash(在JavaScript中)迭代生日:

_(obj.today_birthdays).forEach(function(birthday) {
    //use birthday var..
}