处理由Microsoft Academic Knowledge API生成的格式错误的JSON

时间:2017-10-31 01:13:00

标签: json microsoft-cognitive

向Microsoft Academic发出以下请求会产生格式错误的JSON:

https://westus.api.cognitive.microsoft.com/academic/v1.0/interpret?
query=albert einstein&complete=0&count=2&offset=2&model=latest

结果如下

Request-Context: appId=cid-v1:7cd06f0e-6d73-46a5-9c10-4ebe681d0156
apim-request-id: 8eec6818-55d3-4b7c-b1c3-b4c6236f0173
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
x-content-type-options: nosniff
Date: Tue, 31 Oct 2017 01:02:11 GMT
X-Powered-By: ASP.NET
Content-Length: 681
Content-Type: application/json

{
"query": "albert einstein",
"interpretations": [,
{
  "logprob": -69.749,
  "parse": "<rule name=\"#GetPapers\"><attr name=\"academic#W\">albert</attr> <attr name=\"academic#F.FN\">einstein</attr></rule>",
  "rules": [{
    "name": "#GetPapers",
    "output": {
      "type": "query",
      "value": "And(W='albert',Composite(F.FN=='einstein'))"
    }
  }]
},
{
  "logprob": -118.575,
  "parse": "<rule name=\"#GetPapers\"><attr name=\"academic#W\">albert</attr> <attr name=\"academic#W\">einstein</attr></rule>",
  "rules": [{
    "name": "#GetPapers",
    "output": {
      "type": "query",
      "value": "And(W='albert',W='einstein')"
    }
  }]
}
]
}

注意JSON第三行的前导逗号,位于interpretations数组的开头。我怀疑用于分页结果的代码中存在一个错误。我在Python中工作,并且那个领先的逗号会破坏我能想到的每个解析器,包括一个直的eval。我想在使用json.loads之前我可以使用String.replace处理它,但这是一个丑陋的解决方案。还有更好的选择吗?我是否认为这是一个错误?

0 个答案:

没有答案