有两行 JSON 数据存储为字符串
First Row - {"content":[{"title":"Test1","desc":"Team1","image":"http://team.jpg"}],"leftnav":[{"navtitle":"Nav One","navdesc":"One Link","navimage":"http://plan.jpg"}]}
Second Row - {"content":[{"title":"Test2","desc":"Team2","image":"http://group.jpg"}],"leftnav":[{"navtitle":"Nav Two","navdesc":"Two Link","navimage":"http://graph.jpg"}]}
使用每个函数,我正在遍历每一行并尝试访问数据,如下所示
其中“resultRegionArr”是对象的对象
$(resultRegionArr).each(function(x){
var str = resultRegionArr[x].testdata;// str is assigned each row at a time
var finalobj = JSON.parse(str); // String is been converted to objects
alert(finalobj.leftnav[x].navtitle);
}
对于第一次迭代,即 finalobj.leftnav[0].navtitle 我能够得到正确的结果 - Nav One
第二次迭代,即 finalobj.leftnav[1].navtitle 我得到一个错误 finalobj.leftnav[x] 没有定义。
提前致谢