json转为jsonObject对象失败

通过客户提供的接口,在后台我使用http请求接口的方式获得接口数据(接口数据的格式为json)
图片说明
返回的json数据实例
[{"id":"150","channelId":"126","titleZhtw":"深度財經專題","titleZhcn":"深度财经专题","contentZhtw":"王牌節目。從上市公司到財經事件,獨到分析兩岸、全球每一個熱議的財經話題。\n\n播出時間:逢週五播出一集","contentZhcn":"王牌节目。从上市公司到财经事件,独到分析两岸、全球每一个热议的财经话题。\n\n播出时间:逢周五播出一集","broadcastTimeZhtw":"播出時間:逢週五播出一集","broadcastTimeZhcn":"播出时间:逢週五播出一集","image":[{"imageHDBig":"http:\/\/fs.fintv.hk\/category\/150\/image\/0_0.jpg?161017152047","imageHDSmall":"http:\/\/fs.fintv.hk\/category\/150\/image\/0_1.jpg?161017152047","imageLDBig":"http:\/\/fs.fintv.hk\/category\/150\/image\/0_0.jpg?161017152047","imageLDSmall":"http:\/\/fs.fintv.hk\/category\/150\/image\/0_1.jpg?161017152047"}],"status":"APPROVED","isDefault":"1","position":"0","defaultOrder":"198","displayOrder":"1","displayDay":"0","showInZhtw":"1","showInZhcn":"1","createUserId":"91","lastModifyUserId":"1","createTime":"2016-03-22 19:27:42","lastModifyTime":"2016-10-17 15:20:47"}
提示错误
图片说明
fastjson版本1.1.41

恩,肯定会失败,最后少了一个"]"符号

厄,是你少粘贴了,还是怎么,开头有[,结尾没有],格式不对啊,你可以把json,放到网上的在线解析器上看看,能不能格式化

你的json字符串格式不正确,少了一个中括号

 [{
        "id": "150",
        "channelId": "126",
        "titleZhtw": "深度財經專題",
        "titleZhcn": "深度财经专题",
        "contentZhtw": "王牌節目。從上市公司到財經事件,獨到分析兩岸、全球每一個熱議的財經話題。\n\n播出時間:逢週五播出一集",
        "contentZhcn": "王牌节目。从上市公司到财经事件,独到分析两岸、全球每一个热议的财经话题。\n\n播出时间:逢周五播出一集",
        "broadcastTimeZhtw": "播出時間:逢週五播出一集",
        "broadcastTimeZhcn": "播出时间:逢週五播出一集",
        "image": [{
                "imageHDBig": "http:\/\/fs.fintv.hk\/category\/150\/image\/0_0.jpg?161017152047",
                "imageHDSmall": "http:\/\/fs.fintv.hk\/category\/150\/image\/0_1.jpg?161017152047",
                "imageLDBig": "http:\/\/fs.fintv.hk\/category\/150\/image\/0_0.jpg?161017152047",
                "imageLDSmall": "http:\/\/fs.fintv.hk\/category\/150\/image\/0_1.jpg?161017152047"
            }
        ],
        "status": "APPROVED",
        "isDefault": "1",
        "position": "0",
        "defaultOrder": "198",
        "displayOrder": "1",
        "displayDay": "0",
        "showInZhtw": "1",
        "showInZhcn": "1",
        "createUserId": "91",
        "lastModifyUserId": "1",
        "createTime": "2016-03-22 19:27:42",
        "lastModifyTime": "2016-10-17 15:20:47"
    }
]

json格式本来就就不正确 捏可以 将你需要转的json字符串 到json验证器中进行验证

你接收到的字符串有[],表明是个json数组啊,那么首先需要转换成JSONArray,然后再for循环转换成JSONObject,其次先检查需要转换的string 是否是正确的string,测试代码如下,请参考:import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class TestJson {
public static void main(String[] args) {
String change = "[{'id':'150','channelId':'126','titleZhtw':'深度財經專題','titleZhcn':'深度财经专题','contentZhtw':'王牌節目。從上市公司到財經事件,獨到分析兩岸、全球每一個熱議的財經話題。\n\n播出時間:逢週五播出一集','contentZhcn':'王牌节目。从上市公司到财经事件,独到分析两岸、全球每一个热议的财经话题。\n\n播出时间:逢周五播出一集','broadcastTimeZhtw':'播出時間:逢週五播出一集','broadcastTimeZhcn':'播出时间:逢週五播出一集','image':[{'imageHDBig':'http://fs.fintv.hk/category/150/image/0_0.jpg?161017152047','imageHDSmall':'http://fs.fintv.hk/category/150/image/0_1.jpg?161017152047','imageLDBig':'http://fs.fintv.hk/category/150/image/0_0.jpg?161017152047','imageLDSmall':'http://fs.fintv.hk/category/150/image/0_1.jpg?161017152047'}],'status':'APPROVED','isDefault':'1','position':'0','defaultOrder':'198','displayOrder':'1','displayDay':'0','showInZhtw':'1','showInZhcn':'1','createUserId':'91','lastModifyUserId':'1','createTime':'2016-03-22 19:27:42','lastModifyTime':'2016-10-17 15:20:47'}]";
JSONArray arr = JSONArray.parseArray(change);
System.out.println(arr);

    for (int i = 0; i < arr.size(); i++) {
        JSONObject obj = arr.getJSONObject(i);
        System.out.println(obj);
    }

}

}

假设楼主的json少贴了,json里面应该是个数组形式吧? 因为开头就是‘[’,结尾也应该‘]’,那么这个json不应该转为jsonObject,应该转为jsonArray的啊【我没管大小写,相信楼主认得】

你这个是个Array,需要转成JSONArray