开发者

Get object within JSON object only by knowing its position, and not name

I'm currently looking into the Twitter-API - specifically the daily trends-API (http://search.twitter.com/trends/current.json).

Example return from Twitter

{
      trends: {
            2009-11-19 14:29:16: [
                  { 
                      name: "#nottosayonfirstdate",
                      query: "#nottosayonfirstdate"
                  },
                  {
                      name: "New Moon",
                      query: ""New Moon""
                  },
                  {
                      name: "#justbecause",
                      query: "#justbecause"
                  }
            ]
        }
}

I wonder how I can return the values within there without knowing the exact date at the time of the call, since it won't be possible to synchronise the client-time with the server-time.

Normally, I'd go for trends.something[1].name to get the name, but since the timestamp will cha开发者_如何转开发nge all the time, how can I get it when trends is no array?


you can use this:

for (var i in trends) {
    alert (i);                 // "2009-11-19 14:29:16"
    alert (trends[i][0].name); // "#nottosayonfirstdate"
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜