Skip to content Skip to sidebar Skip to footer

Android: The Method Getjsonobject(int) In The Type Jsonarray Is Not Applicable For The Arguments (string)

I do not find my error. Eclipse tell me: The method getJSONObject(int) in the type JSONArray is not applicable for the arguments (String) I want to access: matchdata -> goals -&

Solution 1:

you need to change openbuli.getJSONObject("goal"); to openbuli.getJSONObject(0);
and add getJSONObject("goals") to get the object goals from the first place in the array

String result = "";
SONObject jArray = null;

jArray = new JSONObject(result);

                JSONObject json = (JSONObject) jArray;                 
                JSONArray openbuli = json.getJSONArray("matchdata");

                JSONObject goal = openbuli.getJSONObject(0);
                JSONArray goals = goal.getJSONObject("goals").getJSONArray("goal");          

                 // loop array
                for(int i=0;i<goals.length();i++) {    
                                JSONObject e = goals.getJSONObject(i);
                                Log.e("Name", e.getString("goal_getter_name").toString());
                        }

Post a Comment for "Android: The Method Getjsonobject(int) In The Type Jsonarray Is Not Applicable For The Arguments (string)"