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.

Sandip Armal Patil
  • 6,241
  • 21
  • 93
  • 160

2 Answers2

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.

Yauraw Gadav
  • 1,706
  • 1
  • 18
  • 39
ρяσѕρєя K
  • 132,198
  • 53
  • 198
  • 213
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.

Pratik
  • 1,531
  • 3
  • 25
  • 57