我一直在试图弄清楚为什么从字符串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,但似乎不起作用。
任何原因吗?
答案 0 :(得分:0)
这很好用
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\"}}";
try
{
JSONObject jsonObject = new JSONObject(json);
Log.i("TAG", "a: "+jsonObject.toString());
} catch (JSONException e)
{
e.printStackTrace();
}
您在哪里遇到错误