2016-03-28 84 views
-3
returnLogin([{ 
    "id": 0, 
    "first_name": "abc", 
    "last_name": "xyz", 
    "msg": "Invalid User or Location ID or Password.", 
    "location_id": "", 
}]) 

如何从上面获取数据Json字符串? 在这里json以witn字符串开头没有任何括号这就是为什么我试图。获取数据android json以字符串开头

+0

你甚至尝试过吗?显示您的代码 –

+0

try {JSONObject jsonObject = new JSONObject(response); System.out.println(“jsonResponse”+ jsonObject); (JSONException e){ e.printStackTrace(); } – Manish

回答

0

可以解析如下图所示,

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(); 
     } 

但在此之前解析更正数据。

+0

它进入JSONexception :: org.json.JSONException:值returnLogin(类型java.lang.String不能转换为JSONArray – Manish

+0

因为你的数据有错请纠正, –

+0

请把你原来的json数据, –

相关问题