I have a result from PHP as JSONObject
{"Requests":[{"fromid":"theDude"},{"fromid":"vishaliopeepak@gmail.com"}],"success":1}
I want to get the from ids intro String array in Android?. I have seen other examples but im unable to get it right.
I have a result from PHP as JSONObject
{"Requests":[{"fromid":"theDude"},{"fromid":"vishaliopeepak@gmail.com"}],"success":1}
I want to get the from ids intro String array in Android?. I have seen other examples but im unable to get it right.
Try this
String response = "{'Requests':[{'fromid':'theDude'},{'fromid':'vishaliopeepak@gmail.com'}],'success':1}";
JSONObject obj;
try {
obj = new JSONObject(response);
JSONArray jarray = obj.getJSONArray("Requests");
String success = obj.getString("success");
if (success.equals("1")) {
for (int i = 0; i < jarray.length(); i++) {
JSONObject Jobj = jarray.getJSONObject(i);
if(Jobj.has("fromid"))
Log.i("fromid", Jobj.getString("fromid") + "fromid");
}
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}