Froodle
Froodle

Reputation: 349

Json parsing 2d array android

I currently am trying to parse the data from a website

json http://pastebin.com/5DZ5tnTu

xml (i find this easier to read) http://pastebin.com/PPvTEjMv

and i am using the code

        JSONObject jObject = new JSONObject(json);
        JSONArray jArray = jObject.getJSONArray("articles");
        for (int i=0; i < jArray.length(); i++)
        {
            try {
                JSONObject oneObject = jArray.getJSONObject(i);

                String oneObjectsItem = oneObject.getString("title");
                String oneObjectsItem2 = oneObject.getString("cps_id");

                JSONArray jArray2 = jObject.getJSONArray("articles/image");
                JSONObject oneObject2 = jArray2.getJSONObject(0);
                String oneObjectsItem3 = oneObject2.getString("src");



                Log.i("DATA" ,oneObjectsItem );
                Log.i("DATA2" ,oneObjectsItem2 );
                Log.i("DATA3" ,oneObjectsItem3  );
            } catch (JSONException e) {
                Log.e("ERROR", e.getMessage());

I am unaware of how to get the "src" data, i tried sorting it into a second array but the / was not recognized

Upvotes: 0

Views: 374

Answers (1)

Gabe Sechan
Gabe Sechan

Reputation: 93589

You need to get the image as an object, then get src from it.

JSONObect image = oneObject.getJSONObject("image");
String src = image.getString("src");

Upvotes: 1

Related Questions