-1

我正在尝试从 mysql 数据库中获取一些数据到 android。在下面的代码中,使用“tagconvertstr”在 logcat 上显示了输出,但是出现了一个错误,即字符串无法转换为 json 对象。

try
{
    Log.i("tagconvertstr", "["+result+"]");
    JSONObject json_data = new JSONObject("question");
    name=(json_data.getString("question"));                         
    newq(name);

}
catch(Exception e)
{
    Log.e("Fail 3", e.toString());
}
4

2 回答 2

0

尝试这个,

try {
                    Log.i("tagconvertstr", "["+result+"]");
                    JSONArray jsonResult = new JSONArray(result);

        JSONObject jsonObject=jsonArray.getJSONObject(0).getJSONObject("question");

                name=jsonObject.getString("question");
        newq(name);

                }
                catch(Exception e)
                {
                    Log.e("Fail 3", e.toString());
                }
于 2013-11-06T06:42:21.077 回答
0

尝试这个:-

 JSONObject json_data = new JSONObject(response.toString());
 String responseserver = json_data.getString("responseCode");     
 System.out.println(responseserver);
于 2013-11-06T09:30:02.393 回答