json - Json - 字符串不能转换为 java.lang.Integer
问题描述
尝试将 json 值 (-3) 与列表值 (-3) 进行比较时出现以下错误。该代码适用于正 json 值:
错误:java.lang.ClassCastException:java.lang.String 无法转换为 java.lang.Integer
我尝试将值转换为字符串、整数等。每次我得到相同的错误。
杰森:
[
{
"Name”:”Delayed”,
"ID":-3,
"Ascending":true,
"LocalDateTime":"2019-06-14T07:00:00+09:00",
"EpochDateTime":1560463200,
"Value":10.0,
"Category":"Very Unlikely",
"CategoryValue":5,
}
]
代码:
for (item in indiceId) {
GlobalVariable.indice_id = item
idResponse = WS.sendRequest(findTestObject('Object Repository/API/itemsAPI/items_location_id'))
parsedJsonId = new groovy.json.JsonSlurper().parseText(idResponse.getResponseBodyContent())
if (parsedJsonId[0].ID == item) {
KeywordUtil.markPassed(" Items Response by ID: " + parsedJsonId[0].ID + " Expected: " + item)
}
else {
KeywordUtil.markFailed(" Items Response by ID: " + parsedJsonId[0].ID + " Expected: " + item)
}
}
错误:java.lang.ClassCastException:java.lang.String 无法转换为 java.lang.Integer
解决方案
parsedJsonId = Integer.parseInt(new groovy.json.JsonSlurper().parseText(idResponse.getResponseBodyContent()))
推荐阅读
- node.js - meth app.post 中的多个查询
- ios - ARKit 如何绘制测量刻度
- r - 如何在 R 中制作具有数百个 y 变量的散点图?
- google-earth-engine - 尝试在 Google 地球引擎上上传 shapefile 时出现内部错误
- timer - 如何在颤动中停止计时器?
- javascript - Vue.js:访问数组中的第一项不起作用
- docker - Docker镜像自定义nginx.conf
- vba - 遍历目录并获取具有最高修订号的文件
- java - 如何使用使用 apache StAXOMBuilder 创建的文档元素将 xml 元素映射到 POJO?
- javascript - 如何仅使用 javascript 为指定链接隐藏网页中的元素?