【发布时间】:2018-07-21 02:00:41
【问题描述】:
我一直在试图弄清楚为什么从字符串 json 构造 org.json.JSONObject 不会工作很长时间。
这里是json字符串(漂亮)
{
"status": 200,
"message": "200 Request is valid",
"job": {
"Id": 1,
"Jobtitle": "Test Job",
"Description": "Asthma",
"Medicalcondition": "Asthma",
"Language": "English",
"Racereligion": "Chinese",
"Agegender": "50, Female",
"Hourlyprice": 42,
"Type": "caregiver",
"Date": "2019-05-12T00:00:00+08:00",
"Starttime": "2018-07-20T12:15:00+08:00",
"Endtime": "2018-07-20T18:15:00+08:00",
"Address": "1 Cluny Road",
"Latitude": 1.3152057,
"Longitude": 103.8162553,
"Creator": "xiurobert"
}
}
并缩小(我试图从中构造 JSONObject 的那个)
String json = "{\"status\":200,\"message\":\"200 Request is valid\",\"job\":{\"Id\":1,\"Jobtitle\":\"Test Job\",\"Description\":\"Asthma\",\"Medicalcondition\":\"Asthma\",\"Language\":\"English\",\"Racereligion\":\"Chinese\",\"Agegender\":\"50, Female\",\"Hourlyprice\":42,\"Type\":\"caregiver\",\"Date\":\"2019-05-12T00:00:00+08:00\",\"Starttime\":\"2018-07-20T12:15:00+08:00\",\"Endtime\":\"2018-07-20T18:15:00+08:00\",\"Address\":\"1 Cluny Road\",\"Latitude\":1.3152057,\"Longitude\":103.8162553,\"Creator\":\"xiurobert\"}}";
构造函数
JSONObject jsonObject = new JSONObject(json)
但是,这导致java.lang.RuntimeException: Cannot evaluate org.json.JSONObject.toString()
我什至尝试过先使用 gson 解析字符串,然后将其输出回新的 JSONObject,但似乎不起作用。
有什么原因吗?
【问题讨论】:
-
您使用的是哪个版本的库?我无法在 json-20180130.jar mvnrepository.com/artifact/org.json/json/20180130 中重现该问题
-
@karthick 我正在使用与 android api 26 捆绑的那个。不确定会是哪一个
标签: java android json org.json