-4

I have the following json:

 {
     "code": "1",
     "status": "OK",
     "users": [
         {
             "id": "5",
             "yazi": "launcher",
             "gun": "2015-08-04"
         },
         {
             "id": "6",
             "yazi": "piano",
             "gun": "2015-02-02"
         },
         {
             "id": "9",
             "yazi": "text text",
             "gun": "2015-08-05"
         },
         {
             "id": "14",
             "yazi": null
             "gun": "2015-02-02"
         }
     ] }

i want to if code is "1" and status is "OK" then view users parameter. What should I used?

Jaiprakash Soni
  • 4,100
  • 5
  • 36
  • 67
Dynasty
  • 29
  • 4
  • Check this for json parsing http://stackoverflow.com/questions/9605913/how-to-parse-json-in-android – Rohit5k2 Aug 17 '15 at 07:33
  • JSONObject obj=new JSONObject(); String status=obj.getString("status"); String code=obj.getString("code"); if(code.equalsIgnoreCase("1") && status.equalsIgnoreCase("OK")) { JSONArray users = object.getJSONArray("users"); for(int i=0;i – Neha Tyagi Aug 17 '15 at 08:45

2 Answers2

0

use this

    JSONObject obj=new JSONObject();
    String status=obj.getString("status");
    String code=obj.getString("code");
    if(code.equalsIgnoreCase("1") && status.equalsIgnoreCase("OK"))
    {
        //Parse your users array
    }
Ravi
  • 34,851
  • 21
  • 122
  • 183
0

Here is the code to parse a JSONObject:

    JSONObject object = new JSONObject(jsonString);
    String code = object.optString("code");
    String status = object.optString("status");
    if (code.equals("1") && status.equals("OK")) {
        JSONArray users = object.getJSONArray("users");
        // do your code 
    }
Wesley
  • 4,084
  • 6
  • 37
  • 60