开发者

ParsingJSON without any keys in jQuery

开发者 https://www.devze.com 2023-01-09 23:33 出处:网络
I\'m playing around with the twitter API and it\'s returning the following: [ 12345, 12345, 12345, 12345 ]

I'm playing around with the twitter API and it's returning the following:

[ 12345, 12345, 12345, 12345 ]

How do I go about parsing this into an array or object?

I can't see how to do it using $.getJSON as there are no keys to reference the开发者_Python百科 data with.

Any help would be greatly appreciated, cheers.


You won't need keys in this case, in your success function just loop through they array, for example:

$.getJSON(url, function(data) {
  $.each(data, function(i, id) {
    alert('ID #' + i + ' is ' + id);
  });
});

They point is the object might already be an array, so just loop through it, it doesn't need to be data.key[0], it may just be data[0], which is what you have here :)


you could use that return to create an array.

$arr = [ 12345, 12345, 12345, 12345 ]

0

精彩评论

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