-1

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.

coderVishal
  • 8,369
  • 3
  • 35
  • 56

1 Answers1

0

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();
    }
Shini
  • 573
  • 4
  • 11