如何解决这个问题,字符串无法转换为JSONObject?

时间:2016-02-09 05:57:25

标签: java android json

我是android学习,我正在使用Json解析并得到如下问题如何解决这个问题?

org.json.JSONException:类型java.lang.String的值SELECT无法转换为JSONObject

这是我的代码

  {"status": 1,
  "msg": "success",
  "errorCode": "",
  "errorDesc": "",
  "data": [
    {
      "sdate": "2016-02-05",
      "ID": "3366",
      "post_title": "Guided Tours of Louis Armstrong House",
      "post_date": "2016-01-15 18:30:30",
      "description": "\r\n\tEvery Friday\r\n",
      "post_content": "\r\n\tEvery Friday\r\n",
      "guid": "http://hothousejazz.com/event_detail.php?eid=3366",
      "start_date": "2016-02-05",
      "end_date": "2016-03-04",
      "evo_hide_endtime": "No",
      "venue": "Queens",
      "location": "34-56 107th Street, Corona, NY",
      "geo_location": "34-56 107th Street, Corona, NY",
      "latitude": "40.754596",
      "longitude": "-73.8613472",
      "phone": "718-478-8274",
      "stime": "10:00 AM",
      "etime": "05:00 PM",
      "website": "http://www.louisarmstronghouse.org"
    }

这是我的json回复

02-09 01:12:41.399 1979-2009/? W/System.err: org.json.JSONException: Value SELECT of type java.lang.String cannot be converted to JSONObject

这是log

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <solid android:color="@color/gray" />
    </shape>
</item>

<item
    android:bottom="1px"
    android:left="0px">
    <shape android:shape="rectangle" >
        <solid android:color="#FFFFFF" />
    </shape>
</item>

</layer-list>

2 个答案:

答案 0 :(得分:1)

Jsonobject jsonobj=new Jsonobject(response)
Jsonarray jsonarray=new Jsonarray(jsonobj.getString("status"));
for(int i=0;i<jsonarray.length();i++)
{
Here you can fetch the  other values inside Jsonarray

}

这是解析json的方法但你的json格式不正确请看看它

答案 1 :(得分:0)

这样的数据

 JSONObject jsonObject = new JSONObject(response);

 String  status = jsonObject.getString("msg");
  if (status.equals("success")){

  JSONArray cast = jsonObject.getJSONArray("data");

  for (int i=0; i<cast.length(); i++){

  JSONObject actor2 = cast.getJSONObject(i);
  String name =actor2.getString("sdate");
  String note = actor2.getString("id");
  String point = actor2.getString("post_title");
  String has_image = actor2.getString("post_date");

}

试试这个。