2
 [{"Episode Detail":[{"Episode-image":"http:\/\/app.lionforge.com\/comics\/adminpanel\/episode_image\/014929Quincredible_1-6.png","Episode-description":" dsdsdsdsds ","Episode-video":"http:\/\/www.youtube.com\/embed\/KhXTLAdadlw"},{"Episode-image":"http:\/\/app.lionforge.com\/comics\/adminpanel\/episode_image\/015041Quincredible_1-5.png","Episode-description":" avbcabc ","Episode-video":"http:\/\/www.youtube.com\/embed\/5ORBHSJhXew"}]}]


   JSONObject jObject=null;
    try {
        jObject = new JSONObject(response);
        JSONArray list = jObject.getJSONArray("Episode Detail");

        for (int i = 0; i < list.length(); i++) {
            JSONObject element = list.getJSONObject(i);
                episodebean bean=new episodebean();

i am getting json exception that JSONArray cannot be converted to JSONObject,how i resolve this ,i am so confuse..,please help me..

1
  • 5
    You should accept one of the below answer that helped you most as it seems your problem solved. and you have asked nearly 10 questions and accepted none... Commented Jan 20, 2014 at 11:36

5 Answers 5

4

use following code

JSONObject jObject=null;
    try {
        JSONArray array = new JsonArray(response)
        jObject = jsonArray.getJSONObject(0);
        JSONArray list = jObject.getJSONArray("Episode Detail");

        for (int i = 0; i < list.length(); i++) {
            JSONObject element = list.getJSONObject(i);
                episodebean bean=new episodebean();

your have one jsonArray that has one JsonObject

Sign up to request clarification or add additional context in comments.

Comments

3

Change this

jObject = new JSONObject(response);

To

 JSONArray jarray = new JSONArray(response);

JSON

[  //json array node 
    { // json object node 
        "Episode Detail": [ // json array episode detail
            {            // json obect node j
                "Episode-image":  "http://app.lionforge.com/comics/adminpanel/episode_image/014929Quincredible_1-6.png", 
                "Episode-description": " dsdsdsdsds ",
                "Episode-video": "http://www.youtube.com/embed/KhXTLAdadlw"
            },
            {
                "Episode-image": "http://app.lionforge.com/comics/adminpanel/episode_image/015041Quincredible_1-5.png",
                "Episode-description": " avbcabc ",
                "Episode-video": "http://www.youtube.com/embed/5ORBHSJhXew"
            }
        ]
    }
]

Comments

3
JSONArray arr  = new JSONArray("");
    for (int i = 0; i < arr.length(); i++) {
        JSONObject c = json_data.getJSONObject(i);
        JSONArray arrdata = c.getJSONArray("Episode Detail");
    }

Comments

2

The root of your JSON is an JSONArray

Comments

0

response is Array not object.

jObject = new JSONObject(response);

it should be Array instead of object

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.