android org.json.JSONArray无法转换为JSONObject?

时间:2014-01-20 11:22:40

标签: android

 [{"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();

我得到json异常,JSONArray无法转换为JSONObject,我如何解决这个问题,我很困惑..,请帮助我..

5 个答案:

答案 0 :(得分:4)

使用以下代码

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();

您有一个jsonArray有一个JsonObject

答案 1 :(得分:3)

更改此

jObject = new JSONObject(response);

 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"
            }
        ]
    }
]

答案 2 :(得分: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");
    }

答案 3 :(得分:2)

JSON的根目录是JSONArray

答案 4 :(得分:0)

响应是数组不是对象。

jObject = new JSONObject(response);

它应该是Array而不是object