2 qq 28717427 qq_28717427 于 2016.03.09 09:30 提问

解析key为json字符串时,抛出JSON keys must be strings 异常

跟客户对接,用json格式传输数据。

客户传过来的json串如这种:{"failedMap":{"{\"content\":\"test 1\",\"mobileNum\":\"13548546858\",\"refer\":\"test\",\"time\":1457436775000,\"token\":-2452365047050524154}":"ERROR"},"successMap":{"{\"content\":\"test 1\",\"mobileNum\":\"13548546850\",\"refer\":\"test\",\"time\":1457436774000,\"token\":-144685337407813035}":"SUCCESS","{\"content\":\"test 1\",\"mobileNum\":\"13548546853\",\"refer\":\"test\",\"time\":1457436775000,\"token\":9148477391415919012}":"SUCCESS"}}

我引用 json-lib-2.3-jdk15.jar 中JSONObject 进行解析,抛出JSON keys must be strings 异常,我在下面贴出解析方式和异常详细信息

9个回答

dcxy0
dcxy0   Ds   Rxr 2016.03.09 09:39
 {"failedMap":{"{"content":"test 1","mobileNum":"13548546858","refer":"test","time":1457436775000,"token":-2452365047050524154}":"ERROR"},"successMap":{"{"content":"test 1","mobileNum":"13548546850","refer":"test","time":1457436774000,"token":-144685337407813035}":"SUCCESS","{"content":"test 1","mobileNum":"13548546853","refer":"test","time":1457436775000,"token":9148477391415919012}":"SUCCESS"}}

去掉你那个"\"的之后的格式,有问题http://json.cn/可以检查json是否有错误.

qq_28717427
qq_28717427   2016.03.09 09:33

图中 responseJson是客户回传过来的json串

qq_28717427
qq_28717427   2016.03.09 09:33

图片说明

qq_28717427
qq_28717427   2016.03.09 09:34

图片说明
这是解析的方法

qq_28717427
qq_28717427   2016.03.09 09:36

图片说明
异常

qq_28717427
qq_28717427   2016.03.09 09:36

图片说明
异常

xdshengk
xdshengk   2016.03.09 09:39

jason的值也要用双引号括起来,明显发过来的不是jason的格式

kangliang1230
kangliang1230   2016.03.09 10:04

{
"failedMap": {
"{\"content\":\"test 1\",\"mobileNum\":\"13548546858\",\"refer\":\"test\",\"time\":1457436775000,\"token\":-2452365047050524154}": "ERROR"
},
"successMap": {
"{\"content\":\"test 1\",\"mobileNum\":\"13548546850\",\"refer\":\"test\",\"time\":1457436774000,\"token\":-144685337407813035}": "SUCCESS",
"{\"content\":\"test 1\",\"mobileNum\":\"13548546853\",\"refer\":\"test\",\"time\":1457436775000,\"token\":9148477391415919012}": "SUCCESS"
}
}

老夫装逼一生从未见过这种json格式、

xionglangs
xionglangs   Rxr 2016.03.09 10:33

这个跟你的差不多。http://my.oschina.net/heweipo/blog/368116

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!