Dave
Dave

Reputation: 923

JsonObject gives typeMisMatch error

I am getting a JSON.typeMisMatch error on line 3 below in my android app. I don't understand why because I am able to access this array in other programs.

         1   JSONObject jsonObj = new JSONObject(result);
         2   Log.d("jsonObj=", String.valueOf(jsonObj));
         3   JSONArray jsonArray = jsonObj.getJSONArray("obit"); // This is the error line
         4   JSONObject jsonObit = jsonArray.getJSONObject(0);

            obituary = jsonObit.getString(("Obit"));

Below is a console display of line 2:

        D/jsonObj=﹕ {"obit":{"Obit":"John R. Uphoff, 94, of Heritage Manor of Minonk, died at 1:18 a.m. Thursday ...

And here is the error I get:

         org.json.JSONException: Value {"Obit":"John R. Uphoff, 94, of Heritage Manor of Minonk, died 

I have accessed this json string in other programs but get an error in this situation. Does anyone know why this error occurrs?

Upvotes: 1

Views: 98

Answers (1)

Chitrang
Chitrang

Reputation: 5097

That is another JSONObject,

JSONArray jsonArray = jsonObj.getJSONArray("obit"); 

Replace it with,

JSONObject jsonOuterObit = jsonObj.getJSONObject("obit"); 

and then get a string,

obituary = jsonOuterObit.getString(("Obit"));

Upvotes: 1

Related Questions