ParsingJSON without any keys in jQuery
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 ]
精彩评论