Reputation:
Here is my Json response:
{
"value": [
{
"type": "school",
"id": 12,
"name": "NNPS",
"city": "CA",
"geo_position": {
"latitude": 52.52437,
"longitude": 13.41053
}
},
{
"type": "College",
"id": 44,
"name": "PEC",
"city": "PE",
"geo_position": {
"latitude": 45.50298,
"longitude": 10.04366
}
}
]
}
Here is my java code using "json.JSONArray" library:
while ((csvdata= br.readLine()) != null) {
JSONObject output= new JSONObject(csvdata);
JSONArray docs = output.getJSONArray("value");
String csv = CDL.toString(docs);
FileUtils.writeStringToFile(file, csv);
}
When i checked csv
file, it shows me like this:
But it should be like this:
I am at very beginning of my coding stage and currently improving it. Please give me some advice on it :)
How should i change it?
Upvotes: 0
Views: 3800
Reputation: 2710
You should set the level of lat and long again. This worked for me
while ((csvdata= br.readLine()) != null) {
JSONObject output= new JSONObject(csvdata);
JSONArray docs = output.getJSONArray("value");
for(int i=0; i<docs.length();i++){
JSONObject geo_pos = (JSONObject)(docs.getJSONObject(i).getJSONObject("geo_position"));
docs.getJSONObject(i).put("latitude", geo_pos.get("latitude"));
docs.getJSONObject(i).put("longitude", geo_pos.get("longitude"));
docs.getJSONObject(i).remove("geo_position");
}
String csv = CDL.toString(docs);
FileUtils.writeStringToFile(file, csv);
}
Upvotes: 1