-4

i have to find the status of the the json response.How can i fetch the status from json array or how can check if the status code of the response is 200

{
    "assetDetails": [
        {
            " assetNo": "rocket",
            "assetName": "VIN Bullet"
        },
        {
            "assetNo": "Asset2",
            "assetName": "VIN Bullet"
        },
        {
            "assetNo": "rocket",
            "assetName": "VIN Bullet"
        }
    ],
    "status": "200"
}
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74
  • You can not use `getstatuscode()` method for get status key from your JSON response, `getstatuscode()` is used to get status code from HTTP response. – Chirag Savsani Feb 13 '17 at 10:37

2 Answers2

0

If you got your response in JSON format. You can try below method.

    try {
        JSONObject jsonObject = new JSONObject(<Your JSON Response>);
        String strStatus = jsonObject.getString("status");

        // Now your status stored in strStatus variable, you can now do any thing with that variable.

    } catch (JSONException je) {
        je.printStackTrace();
    }
Chirag Savsani
  • 6,020
  • 4
  • 38
  • 74
0

Try this,

    try {
        JSONObject obj=new JSONObject(response);
        String status=obj.getString("status");
        if(status.equals("200"))
        {

        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
Komal12
  • 3,340
  • 4
  • 16
  • 25