我有一个类似下面的JSON结构(帖子末尾), 我想从文件中读取它并提取一些信息。我想获取"times"子项并对其进行操作。我尝试使用json.simple和一些jackson库,但是我一直收到转换/类型错误。我很困惑 :/
首先,我读入文件,看起来已经正确捕获:
非常感谢您的帮助!
首先,我读入文件,看起来已经正确捕获:
JSONParser parser = new JSONParser();
JSONObject data = (JSONObject) parser.parse(new FileReader("test.json"));
我尝试跟随这个链接:Java JSONObject get children,但是出现了错误 org.json.simple.JSONArray cannot be cast to org.json.simple.JSONObject
我的目的(认为是这样?)是创建一个时间的JSON,然后可以从中制作时间列表/进行各种操作。或者最好的方法是使用ObjectMapper并将其映射到匹配的对象中?
{
"id": "ca1b57be-6c38-4976-9050-f9a95a05a38d",
"name": "some name",
"results": [
{
"name": "https://st-dev.aexp.com/smart-test/v1/test/test",
"tests": {
"name": "Body matches string",
"status": "pass",
"Response time is less than 200ms": true
},
"testPassFailCounts": {
"Body matches string": {
"pass": 100,
"fail": 0
},
"Response time is less than 200ms": {
"pass": 100,
"fail": 0
}
},
"times": [
"48",
"25",
"25",
"28",
"24",
"24",
"35",
"29",
"41",
"28",
"28",
"24",
"31",
"28",
"25",
"27",
"23",
"28",
"44",
"29",
"25",
"23",
"44",
"28",
"22"
]
}
]
}
非常感谢您的帮助!