0

I want parse json url,my json url contains following structures

{"content":{"item":[{"category":"xxx"},{"category":"yy"} ]}}

how to read this structure,anybody knows give example json parser for that.

Thanks

3 Answers 3

1

This code will help you to parse yours json.

 String jsonStr = "{\"content\":{\"item\":[{\"category\":\"xxx\"},{\"category\":\"yy\"} ]}}";
 try {
        ArrayList<String> categories = new ArrayList<String>();
        JSONObject obj = new JSONObject(jsonStr);
        JSONObject content = obj.getJSONObject("content");
        JSONArray array = content.getJSONArray("item");
        for(int i = 0, count = array.length();i<count;i++)
        {
            JSONObject categoty = array.getJSONObject(i);
            categories.add(categoty.getString("category"));
        }
  } catch (JSONException e) {
        e.printStackTrace();
  }
Sign up to request clarification or add additional context in comments.

Comments

0

JSONObject can do the parsing.

Comments

0

You need to use the org.json's package. Example:

For an object:

JSONObject json = new JSONObject(json_string);

For an array:

JSONArray json = new JSONArray(json_string);

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.