This is the JSON result of my query.
{
"_id":{"$id":"551fb585ecba12c819000032"},
"nome":"Google","loc":[-122.083983,37.422969],
"icona":1,
"istituzione_id":{"$id":"551fb556ecba12c819000031"}
}
{
"_id":{"$id":"5520fe2becba12c003000029"},
"nome":"Oracle","loc":[-122.262168,37.531595],
"icona":1,
"istituzione_id":{"$id":"551fb556ecba12c819000031"}
}
I've tried to parse JSON result in this manner:
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
StringBuilder sb = new StringBuilder();
String line = null;
while ((line = reader.readLine()) != null) {
Log.e("log_a_line", line);
sb.append(line + "\n");
}
is.close();
result = sb.toString();
Log.e("log_a_result", result);
} catch (Exception e)
{
Log.e("log_tag_convert", "Error converting result" + e.toString());
}
//-----PARSER----
try {
JSONArray jArray = new JSONArray(result);
for (int i = -1; i < jArray.length() - 1; i++) {
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag", "id:" + json_data.getString("_id"));
}
}
catch (JSONException e)
{
Log.e("log_tag_parsing", "Error parsing data" + e.toString());
}
But after run the app, in my logcat i found error:
log_tag_parsing﹕ Error parsing dataorg.json.JSONException: Value {"icona":1,"loc":[-122.083983,37.422969],"nome":"Google","istituzione_id":{"$id":"551fb556ecba12c819000031"},"_id":{"$id":"551fb585ecba12c819000032"}} of type org.json.JSONObject cannot be converted to JSONArray
I have thought that the problem was about the subarray loc:[....] maybe.
I can't reach the solution. Someone can help me ?