smriti
smriti

Reputation: 1144

Iterate last values present in a JSON response using java

I need to iterate and get the last values like name, url and color from below JSON response. Using java/gson api. Please help me on this.

    {
  "Title": {
    "desc": [
      {
        "name": "PRE_DB",
        "url": "http://jenkins.example.com/job/my_first_job/",
        "color": "blue_anime"
      },
      {
        "name": "SDD_Seller_Dashboard",
        "url": "http://jenkins.example.com/job/my_second_job/",
        "color": "blue_anime"
      }
    ]
  }
}

example output : name : SDD_Seller_Dashboard color :blue_anime

Upvotes: 0

Views: 90

Answers (1)

AnilCk
AnilCk

Reputation: 106

JSONObject data = new JSONObject(your_JSON_Repsonse);
JSONArray data_desc=data.getJSONArray(desc);
for(int i=0;i<=data_desc.length();i++)
{
 name=data_desc.getString("name");
url=data_desc.getString("url");
color=data_desc.getString("color");
}

Upvotes: 1

Related Questions