admin管理员组文章数量:1391943
I am looping through the following json. I get id and name fine, but when I do json.templates[i].dailyemails.length
it always returns 0.
Here is my json:
{
"templates":[
{
"id":"2c1d99d9b6b2fb417601d24c10c9b041a7d6f37b",
"dailyemails":[
"[email protected]",
"[email protected]"
],
"name":"Registration Report"
},
{
"id":"7d7cc642ca13cc4a998cad364dfe8e623fd95ae3",
"dailyemails":[
"[email protected]"
],
"name":"Live Report"
}
]
}
I am looping through the following json. I get id and name fine, but when I do json.templates[i].dailyemails.length
it always returns 0.
Here is my json:
{
"templates":[
{
"id":"2c1d99d9b6b2fb417601d24c10c9b041a7d6f37b",
"dailyemails":[
"[email protected]",
"[email protected]"
],
"name":"Registration Report"
},
{
"id":"7d7cc642ca13cc4a998cad364dfe8e623fd95ae3",
"dailyemails":[
"[email protected]"
],
"name":"Live Report"
}
]
}
Share
Improve this question
edited Sep 11, 2012 at 15:53
Brian
15.9k7 gold badges37 silver badges43 bronze badges
asked Sep 11, 2012 at 15:39
Pit DiggerPit Digger
9,81023 gold badges81 silver badges126 bronze badges
3 Answers
Reset to default 1If this is JSON, that is a string, you have to parse it and work with a javascript object :
var obj = JSON.parse(json);
And then you may query obj.templates[i].dailyemails
$.each(data.templates,function(index,item){
alert(item.dailyemails.length)
});
Sample : http://jsfiddle/JbF29/2/
This should work just fine as seen in this live demo. Make sure that your actual JSON structure is the same as the one you have shown in your question.
本文标签: javascriptGetting Data from a json sub arrayStack Overflow
版权声明:本文标题:javascript - Getting Data from a json sub array - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744746613a2622919.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论