【发布时间】:2011-04-11 22:11:43
【问题描述】:
我在访问位于我的 JSON 数据集的嵌套数组时需要帮助。这是我的顶级 JSON 数组的第一个条目:
{
"pingFeed": [{
"header": "Get Drinks?",
"picture": "images/joe.jpg",
"location": "Tartine's, SF",
"time": "Tomorrow Night",
"name": "Joe Shmoe",
"pid":
"123441121",
"description": "Let's drop some bills, yal!",
"comments": [{
"author": "Joe S.",
"text": "I'm Thirsty"
},
{
"author": "Adder K.",
"text":
"Uber Narfle"
},
{
"author": "Sargon G.",
"text": "taeber"
},
{
"author": "Randy T.",
"text": "Powdered Sugar"
},
{
"author": "Salvatore D.",
"text":
"Chocolate with Sprinkles"
},
{
"author": "Jeff T.",
"type": "Chocolate"
},
{
"author": "Chris M.",
"text": "Maple"
}],
"joined": false,
"participants": [
"Salvatore G.", "Adder K.", "Boutros G."],
"lat": 37.25,
"long": 122,
"private": true
}]
}
我想知道如何使用以下符号访问 cmets 和参与者数据:
for (var k = 0; k < pingFeed.length ; k++) {
console.log(pingFeed[k].comments);
console.log(pingFeed[k].participants);
}
目前,这种形式的点表示法适用于 JSON 数组中的其他条目... 我希望将所有这些数据作为字符串返回。
【问题讨论】:
-
Tartine 是一家很棒的餐厅,抱歉我无法抗拒。
标签: javascript arrays json