resolve JSONException duplicate keys

后端 未结 3 1705
暖寄归人
暖寄归人 2021-01-19 14:45

i am using google custom search engine and getting the results in JSON format.for certain queries,the JSON result has duplicate keys and hence it produces a JSONException: D

相关标签:
3条回答
  • 2021-01-19 15:16

    You can make use of the Jackson library to parse JSON. I'd problems doing the same task as you with org.json's package, but I turned to Jackson and I solved it: http://wiki.fasterxml.com/JacksonHome

    0 讨论(0)
  • 2021-01-19 15:18

    If you really need this functionality, roll back to gson 1.6. Duplicate keys are allowed in that version.

    0 讨论(0)
  • 2021-01-19 15:22

    JSon object, like any other object, can not have two attribute with same name. That's illegal in the same way as having same key twice in a map.

    JSONObject would throw an exception if you have two keys with same name in one object. You may want to alter your object so that keys are not repeated under same object. Probably consider nickname as an array.

    You need to paste the JSON object in the question.

    0 讨论(0)
提交回复
热议问题