這是我從foursquare得到的JSON的一部分。JQuery從JSON數組中獲取數據
JSON
tips: {
count: 2,
groups: [
{
type: "others",
name: "Tips from others",
count: 2,
items: [
{
id: "4e53cf1e7d8b8e9188e20f00",
createdAt: 1314115358,
text: "najjači fitness centar u gradu",
canonicalUrl: "https://foursquare.com/item/4e53cf1e7d8b8e9188e20f00",
likes: {
count: 2,
groups: [
{
type: "others",
count: 2,
items: []
}],
summary: "2 likes"
},
like: false,
logView: true,
todo: {
count: 0
},
user: {
id: "12855147",
firstName: "Damir",
lastName: "P.",
gender: "male",
photo: {
prefix: "https://irs1.4sqi.net/img/user/",
suffix: "/AYJWDN42LMGGD2QE.jpg"
}
}
},
{
id: "4e549e39152098912f227203",
createdAt: 1314168377,
text: "ajd da vidimo hocu li znati ponoviti",
canonicalUrl: "https://foursquare.com/item/4e549e39152098912f227203",
likes: {
count: 0,
groups: []
},
like: false,
logView: true,
todo: {
count: 0
},
user: {
id: "12855147",
firstName: "Damir",
lastName: "P.",
gender: "male",
photo: {
prefix: "https://irs1.4sqi.net/img/user/",
suffix: "/AYJWDN42LMGGD2QE.jpg"
}
}
}]
}]
}
我需要得到最後一個技巧文本,則用戶誰寫的和日期時,他寫道/張貼。
用戶:達米爾P.
日期:1314115358
文本:najjači健身辛塔爾ü漸亮
我試着用JQuery的和這個作品來獲取非 - 陣列值:
$.getJSON(url, function(data){
var text= data.response.venue.tips.groups.items.text;
alert(text);
});
但它不適用於數組。
結果:Uncaught TypeError:無法讀取未定義的屬性「文本」。
此外我嘗試與$。每個,但沒有效果。
$.getJSON(url, function(data){
$.each(data.response.venue.tips.groups.items.text, function (index, value) {
console.log(value);
});
});
我在做什麼錯了?
@JanDvorak他在這裏學習。無需火焰他。 – Johan 2013-03-05 08:56:30
組也是一個數組。 – SteveP 2013-03-05 08:56:39
@Johan我承認,這是非常制定。儘管如此,我想要的只是將他指向正確的資源。 – 2013-03-05 08:58:36