returnLogin([{
"id": 0,
"first_name": "abc",
"last_name": "xyz",
"msg": "Invalid User or Location ID or Password.",
"location_id": "",
}])
如何从上面获取数据Json字符串? 在这里json以witn字符串开头没有任何括号这就是为什么我试图。获取数据android json以字符串开头
returnLogin([{
"id": 0,
"first_name": "abc",
"last_name": "xyz",
"msg": "Invalid User or Location ID or Password.",
"location_id": "",
}])
如何从上面获取数据Json字符串? 在这里json以witn字符串开头没有任何括号这就是为什么我试图。获取数据android json以字符串开头
可以解析如下图所示,
String data = "";// here your json data which will parse
try {
JSONArray jsonArray = new JSONArray(data);
JSONObject jsonObject=jsonArray.getJSONObject(0);
int id=jsonObject.getInt("id");
String first_name=jsonObject.getString("first_name");
String last_name=jsonObject.getString("last_name");
String msg=jsonObject.getString("msg");
String location_id=jsonObject.getString("location_id");
} catch (JSONException e) {
e.printStackTrace();
}
但在此之前解析更正数据。
它进入JSONexception :: org.json.JSONException:值returnLogin(类型java.lang.String不能转换为JSONArray – Manish
因为你的数据有错请纠正, –
请把你原来的json数据, –
你甚至尝试过吗?显示您的代码 –
try {JSONObject jsonObject = new JSONObject(response); System.out.println(“jsonResponse”+ jsonObject); (JSONException e){ e.printStackTrace(); } – Manish