这是我从Foursquare获取的JSON部分。
JSON(JavaScript Object Notation)
我需要获取最后一个提示文本,以及撰写它的用户和他/她发表时的日期。
用户:Damir P.
日期:1314115358
文本:城市中最棒的健身中心
我尝试使用JQuery,并且这可以获取非数组值。
我做错了什么吗?
JSON(JavaScript Object Notation)
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"
}
}
}]
}]
}
我需要获取最后一个提示文本,以及撰写它的用户和他/她发表时的日期。
用户:Damir P.
日期:1314115358
文本:城市中最棒的健身中心
我尝试使用JQuery,并且这可以获取非数组值。
$.getJSON(url, function(data){
var text= data.response.venue.tips.groups.items.text;
alert(text);
});
但是它不能处理数组。
结果:未捕获的类型错误:无法读取未定义的属性“text”。
我还尝试使用 $.each ,但没有效果。
$.getJSON(url, function(data){
$.each(data.response.venue.tips.groups.items.text, function (index, value) {
console.log(value);
});
});
我做错了什么吗?