java - Is this a correct JSON format {"coord":{"lat":37.4056,"lon":-122.0775}} -


this question has answer here:

i understand correct json format like:

{"coord":[{"lat":37.4056,"lon":-122.0775}]} 

but have data coming me in format

{"coord":{"lat":37.4056,"lon":-122.0775}} 

if correct json format, how parse in java?

in json {} brackets indicates object, while [] ones indicates array.

your first example contains array 1 object containing lat , lon properties, object accessed data.coord[0].lat.
second example object containing object lat , lon properties.
is, no array, object. object accessed data.coord.lat.

both correct json.

you pretty parse them same way, different types (the object or array under coord).

// parse: jsonobject obj = new jsonobject(jsondatastring); // fetching object: jsonobject coord = obj.getjsonobject("coord"); // or fetching array: jsonarray coords = obj.getjsonarray("coord"); 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -