This is part of the JSON i get from foursquare.
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"
}
}
}]
}]
}
I need to get the last tip text , the user who wrote it and the date when he wrote/post it.
User: Damir P.
Date : 1314115358
Text: najja?i fitness centar u gradu
I tried with JQuery and this works to fetch a non-array value:
$.getJSON(url, function(data){
var text= data.response.venue.tips.groups.items.text;
alert(text);
});
But it doesn't work with arrays.
Result : Uncaught TypeError: Cannot read property 'text' of undefined.
Also I tried with $.each, but with no effect.
$.getJSON(url, function(data){
$.each(data.response.venue.tips.groups.items.text, function (index, value) {
console.log(value);
});
});
What am I doing wrong ?
See Question&Answers more detail:
os