解决JSONException重复键

psy*_*psy 4 java json google-search-api

我正在使用谷歌自定义搜索引擎并以JSON格式获取结果.对于某些查询,JSON结果具有重复键,因此它产生一个JSONException:重复键"昵称"等.

我正在使用JAVA.

String str=//contains the query result in json format
JSONObject ob=new JSONObject(str) produces the exception
Run Code Online (Sandbox Code Playgroud)

可能知道如何解决这个异常?

这是JSON的回复:

{
   "kind": "customsearch#result",
   "title": "The World Factbook: India - CIA - The World Factbook",
   "htmlTitle": "The World Factbook: \u003cb\u003eIndia\u003c/b\u003e -",
   "link": "https://www.cia.gov/library/publications/the-world-factbook/geos/in.html",
   "displayLink": "www.cia.gov",
   "snippet": "Jan 20, 2011 ... Features a map and brief descriptions of geography",
   "htmlSnippet": "Jan 20, 2011 \u003",
   "cacheid": "0n2U45w_dvkJ",
   "pagemap": {
    "metatags": [
     {
      "il.secur.classif": "UNCLASSIFIED",
      "il.title": "(U) CIA The World Factbook",
      "il.summary": "CIA - The World Factbook",
      "il.cutdate": "20040101",
      "il.secur.classif": "UNCLASSIFIED",
      "il.title": "(U) CIA The World Factbook",
      "il.cutdate": "20040101",
      "il.secur.classif": "UNCLASSIFIED",
      "il.pubdate": "20040101",
      "il.postdate": "20040501",
      "il.cutdate": "20040101"
     }
    ]
   }
  }
Run Code Online (Sandbox Code Playgroud)

这里il.secur.classif多次出现

Nis*_*ant 6

与任何其他对象一样,JSon对象不能具有两个具有相同名称的属性.这与在地图中两次使用相同密钥的方式相同是非法的.

如果在一个对象中有两个具有相同名称的键,JSONObject将引发异常.您可能希望更改对象,以便不在同一对象下重复键.可能会考虑nickname作为一个数组.

您需要在问题中粘贴JSON对象.