This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 9 years ago.
Hi i am new to json and have some problems in parsing a JSON file with jQuery.
json file is here - http://maps.googleapis.com/maps/api/geocode/json?latlng=27.88,78.08&sensor=false
and i am parsing it like this
var url = "http://maps.googleapis.com/maps/api/geocode/json?latlng=" + area.getCenter().lat + "," + area.getCenter().lng + "&sensor=false";
$.getJSON(url, function(data) {
console.log("insidegetjson");
console.log(data);
var addr = data.results[0].formatted_address[0];
});
here i want to access first "formatted_address" part of the JSON. I know i am making a mistake here (i want "formatted_address" : "Achal Taal, Aligarh, Uttar Pradesh 202001, India",)
var addr = data.results[0].formatted_address[0];
can you please replace this sentence with correct sentence...thanks
Remove the last [0] :
var addr = data.results[0].formatted_address;
data.results[0].formatted_address isn't an array but a string.
Related
This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 3 years ago.
I need convert from data = "[[0,1], [1,1]]" to data = [[0,1], [1,1]] in javascript, remove double quotes . It's possible?
Thanks
Just use the JSON object:
data = JSON.parse("[[0,1], [1,1]]"); // data === [[0,1], [1,1]]
This question already has answers here:
How can I access and process nested objects, arrays, or JSON?
(31 answers)
Closed 4 years ago.
I'm getting data as a json object
var data = JSON.parse(JSON.stringify(data));
console.log(data);
On data console I got this. I want to get key and its value .
{lobby: {…}}
lobby:
8jmb9ca3s04c8el4j5sf0d:"AD8BJBkMKCBoYg_qAAAB"
38cjllj78cx0lic58ujxou:"PX51X9z_M34_9BvtAAAD"
ba8gs1y8779kmakdapxk1:"UowsBDCCsZSpojzPAAAA"
Parse JSON to Object var data = JSON.parse(jsonData);
Use Object.keys(data); to get all keys
Use data.key or data['key'] to get key value.
This question already has answers here:
What is the difference between client-side and server-side programming?
(3 answers)
Closed 7 years ago.
I have a JSON data about 150 users, i have convert that into java script array, now what i want it to pass this array to PHP, So that i can perform further operations on this array.
var JSONString = '[{'user_id' : "1", "user_name" : "abc", "email":"abc#gmail.com"}, {"user_id":"2", "user_name":"abc", "email":"abc2#gmail.com"}]'
var JSONObject = JSON.parse(JSONString);
for (var key in JSONObject) {
if (JSONObject.hasOwnProperty(key)) {
console.log(JSONObject[key]["user_id"] + ", " + JSONObject[key]["user_name"]);
}
}
now what i need it to pass this array to PHP array variable , that will loop through and perform further operation.
i have seen some solution that display it on html with JavaScript, but i don't need that. i need this array object in php array variable.
Instead of parsing JSON string in JavaScript, pass it directly to PHP and use
PHP function
json_decode($json, true)
it will give you data in array format.
This question already has answers here:
How do I return the response from an asynchronous call?
(41 answers)
Closed 8 years ago.
New to nodejs and really programming in general except some basic PHP. I think my problem is more basic javascript than anything though.
How can I access variables 'latitude' and 'longitude' outside the object 'img'?
console.log(latitude + '|' + longitude) is displaying the data I want but in console.log(img) all img properties are empty including exifData.gps.GPSLatitude & exifData.gps.GPSLongitude.
var ExifImage = require('exif').ExifImage;
var img_loc = 'c:/node/test/wherepic/uploaded_imgs/img.JPG';
var img = new ExifImage({ image : img_loc }, function (error, exifData) {
var latitude = exifData.gps.GPSLatitude;
var longitude = exifData.gps.GPSLongitude;
console.log(latitude + '|' + longitude);
});
console.log(img);
The problem is not the object, but the fact that your second console.log is executed before the data becomes available. Only when the function is called that data becomes available. You must access it inside the function.
This question already has answers here:
Parse JSON in JavaScript? [duplicate]
(16 answers)
Closed 10 years ago.
I have this type of JSON:
{"value":[{"idProductCategoryAttributeValue":43,"value":"7","sortOrder":0}]}
I want the individual parameters values like. How do I parse this JSON string in Ext JS 4 or in simple JavaScript?
Have a look at http://docs.sencha.com/ext-js/4-1/#!/api/Ext.JSON. There you find how you can parse JSON with Ext JS 4.
var strJson = '{"value": [{"idProductCategoryAttributeValue":43,"value":"7","sortOrder":0}]}';
var obj = Ext.JSON.decode(strJson);
var obj = Ext.decode(jsonstr);