I've been wondering how to parse JSON Array in android ?
I've a json object like this: [{"ID":"1","email":"[email protected]","password":"password"},{"ID":"2","email":"[email protected]","password":"passward"}]
but I cannot find how to parse it, I want to access data so i could have the first mail, or the second id.
I've try around 40 differents solutions, but no luck.
Last time I tried something it was this:
private void showJSON(String json){
try {
JSONArray jArray = new JSONArray(json);
String JsonString = jArray["ID"];
tv.append(JsonString);
} catch (JSONException e) {e.printStackTrace();}
}
but it expected an array and not a json array. I still haven't found how to convert it into array.
I've also tried this:
for (int i = 0; i < jsonarray.length(); i++) {
JSONObject jsonobject = jsonarray.getJSONObject(i);
String name = jsonobject.getString("email");
}
but getJSONObject doesn't exist.
Thank you for your help.
jsonarrayis not aJSONArray. You may be happier using Gson, Jackson, or other more modern JSON parsing libraries.