Clarence
Clarence

Reputation: 63

Convert object a JSON object to string

I'm trying to convert a json object to a string using but I'm getting 'No Value for NAMES'. My code is as follows:

 JSONObject jsonObject = new JSONObject(resp);
 String c = jsonObject.getString("NAME");
 msg("" + c);

Currently my object is as follows:

{"Names":[{"NAME":"Haircut"},{"NAME":"Blowdry"},{"NAME":"styling "},{"NAME":"treatment "},{"NAME":"braiding"}]}

How can I convert this data so that I may ingest the data into a listview dynamically.

Any help will be highly appreciated.

Upvotes: 0

Views: 558

Answers (1)

Anton Potapov
Anton Potapov

Reputation: 1275

Names is and array in your JSON. So, firstly your should get it. Try this one:

JSONArray names = (JSONArray)jsonObject.get("Names");
((JSONObject) names.get(0)).get("NAME");

Upvotes: 2

Related Questions