1

I know this question has been asked a number of times but I didn't find any relative answer of my question.

I am trying to read json data from asset folder, but I'm getting following exception while getting

I searched number of stuffs but didn't help. Please give me any reference or hint.
Thanks in Advance.

2 Answers 2

4

Use

   String searchedTerm = jsonObject.getString(TAG_SEARCHEDTERM);
   JSONArray results = jsonObject.getJSONArray(TAG_RESULTS); 

instead of

  JSONObject searchedTerm = jsonObject.getJSONObject(TAG_SEARCHEDTERM);
  JSONArray results = searchedTerm.getJSONArray(TAG_RESULTS);  

because TAG_SEARCHEDTERM is key-value pair instead of JSONObject and you are trying to cast a String value to JsonObject.

Sign up to request clarification or add additional context in comments.

Comments

0

I guess you need to get the Dish Name where you are getting exception. You can get the dish name shown below...

String searchedTerm = jsonObject.getString(TAG_SEARCHEDTERM);

Using this

JSONArray results = jsonObject.getJSONArray(TAG_RESULTS);

you will get the "results" JSONArray as shown in your json file.

and you can iterate through it using for loop.

Comments

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.