• 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏吧

如何循环访问这个JSON文件并获取数据?

JavaScript 来源:Cosmin Burlacu 4次浏览

我想追加了“旅游”数据到一个DIV和“自行车”到另一个数据DIV
我也想要得到一个单一的点击事件两种数据结构如何循环访问这个JSON文件并获取数据?

[ 
{ 
    "city1" : { 
     //this is the first data that should be appended to one div 
     "tourism" : [{ 
      "objectId":"1a1", 
      "objectTitle":"title_text", 
      "objectUrl_image":"http://", 
      "object_textContent":"text_content" 
     }, 
     { 
      "objectId":"1a2", 
      "objectTitle":"title_text", 
      "objectUrl_image":"http://", 
      "object_textContent":"text_content" 
     }], 
     //this is another data that should be appended to another div 
     "bikes" : [{ 
      "objectId":"1b1", 
      "objectTitle":"title_text", 
      "objectUrl_image":"http://", 
      "object_textContent":"text_content" 
     }, 
     { 
      "objectId":"1b2", 
      "objectTitle":"title_text", 
      "objectUrl_image":"http://", 
      "object_textContent":"text_content" 
     }] 
    } 
} 
] 


===========解决方案如下:

简单forEach为旅游和自行车性能会做:


版权声明:本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系管理员进行删除。
喜欢 (0)