Reputation: 5905
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.
Upvotes: 1
Views: 4960
Reputation: 1541
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.
Upvotes: 0
Reputation: 132972
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
.
Upvotes: 4