0

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.

1
  • 2
    Names isn't an object, it's an array. Try getJsonArray("Names") and then iterate over it (for loop, etc.) and add its data to a List<String>. Don't have time to post example code but maybe someone else can Commented Aug 1, 2017 at 15:42

1 Answer 1

2

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");
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your help big time. It now works.You've really brighten up my day
@Clarence If this solution worked for you mark it as the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.