解析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 异常,我在下面贴出解析方式和异常详细信息

图中 responseJson是客户回传过来的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"}}

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

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

{
"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格式、

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