我正在使用Zephyr api并且它返回了包含json对象的json数组...
{
"executions": [
{
"id": 24,
"cycleId": 13,
"cycleName": "CLONE - Audit Test Cycle 2",
"issueKey": "ZFJ-2",
"projectKey": "ZFJ",
"project": "ZFJ",
"priority": "Major",
"component": "c1",
"versionId": 10000,
"version": "v1",
"status": {
"id": 2,
"name": "FAIL",
"description": "Test was executed and failed.",
"color": "#CC3300",
"type": 0
},
"executedOn": "18/Oct/13",
"creationDate": "18/Oct/13",
"executedBy": "admin",
"executedByUserName": "admin"
},
{...},
{
"id": 1,
"cycleId": 1,
"cycleName": "Audit Test Cycle",
"issueKey": "ZFJ-2",
"projectKey": "ZFJ",
"project": "ZFJ",
"priority": "Major",
"component": "c1",
"versionId": 10000,
"version": "v1",
"status": {
"id": 1,
"name": "PASS",
"description": "Test was executed and passed successfully.",
"color": "#75B000",
"type": 0
},
"executedOn": "4/Oct/13",
"creationDate": "4/Oct/13",
"executedBy": "admin",
"executedByUserName": "admin"
}
]
最初我使用的是org.json来解析json数组,但是当我解析大约200个json对象时,它似乎很慢。我需要从每个对象中唯一的东西是" id",所以我想通过扫描" id"来解析文档。在每个json对象中,而不是使用org.json来解析整个json响应。
这会改善我的解析性能而不是使用org.json吗?如何在没有解析器的情况下扫描json响应?我假设一个json响应仍然是一行文本,解析器是检索键和值的。
有没有比我建议更好的替代方案?一个更有效的解析器? org.json的性能与其他解析器相比如何?
答案 0 :(得分:1)
手动解析JSON很少是一个好主意。
只需使用已建立的图书馆,就不会出现问题。 Jackson可能是个不错的选择。它显示出良好的性能,并且链接的示例易于遵循。如果您只需要ID字段,则甚至不需要创建复杂的结构(您可以安全地省略其余字段)。