0

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

1
  • 1
    YOur json would be as (or more) easy to read than the xml if you passed it through a pretty printer Commented Mar 19, 2015 at 22:56

1 Answer 1

1

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

JSONObect image = oneObject.getJSONObject("image");
String src = image.getString("src");
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.