I have a JSON
output like the following:
["City1","City2","City3"]
I want to get each of the city names, how can i do this?
$.getJSON("url_with_json_here",function(json){
});
EDIT:
$.getJSON('url_here', function(data){
$.each(data, function (index, value) {
$('#results').append('<p>'+value+'</p>');
console.log(value);
});
});
The above doesn't seem to be working, no values are outputted.
This question is related to
jquery
arrays
json
jquery-mobile
getjson
var dataArray = [];
var obj = jQuery.parseJSON(yourInput);
$.each(obj, function (index, value) {
dataArray.push([value["yourID"].toString(), value["yourValue"] ]);
});
this helps me a lot :-)
var dataArray = [];
var obj = jQuery.parseJSON(response);
for( key in obj )
dataArray.push([key.toString(), obj [key]]);
};
with parse.JSON
var obj = jQuery.parseJSON( '{ "name": "John" }' );
alert( obj.name === "John" );
Use the parseJSON
method:
var json = '["City1","City2","City3"]';
var arr = $.parseJSON(json);
Then you have an array with the city names.
Source: Stackoverflow.com