1
{
"CustomerDetails": [
    {
        "AccountName": "test",
        "DnBNumber": 12342314
    }
]

}

I want to get value from this json object.

I tried below but not working.

jsonObject.getJSONObject("AccountName").toString();
user1037452
  • 411
  • 1
  • 7
  • 15

1 Answers1

0

In the JSON you put, there are a JsonObject that contains a JsonArray, that contains two String, so..

final JSONObject jsonObject = new JSONObject(YOUR_JSON);
final JSONArray jsonArray = obj.getJSONArray("CustomerDetails");

for (int i = 0; i < geodata.length(); ++i) {
  final JSONObject detail = geodata.getJSONObject(i);
  System.out.println(detail.getString("AccountName"));
  System.out.println(detail.getString("DnBNumber"));
}
adalpari
  • 3,052
  • 20
  • 39