究竟如何读取php在android中发送的json对象?

时间:2013-04-12 09:51:50

标签: android json

这是我的代码,用于读取Web应用程序发送到android

的json对象

InputStream instream = entity.getContent();

    String result = "";
    try {
        BufferedReader reader = new BufferedReader(
                new InputStreamReader(instream, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line1 = null;
        while ((line1 = reader.readLine()) != null) {
            sb.append(line1 + "\n");
        }
        instream.close();
        result = sb.toString();
        Log.i("xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");
        Log.i("Read from server", result);
        Log.i("xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");

    } catch (Exception e) {
        Log.e("log_tag", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        JSONObject jArray = new JSONObject(result);
    }

    catch (JSONException e) {
        Log.e("log_tag", "Error parsing data " + e.toString());
    }

} catch (Exception e) {
    Log.i("------resultat---------", "Errrrrrrrrrrrooooooor");
}

但在Logcat中显示结果时,它不会显示

在代码android

中执行此行时
                   Log.i("xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");
      Log.i("Read from server", result);
      Log.i("xxxxxxxxxxxxxxxxxxxxx", "xxxxxxxxxxxxxxxxxxxxxx");

显示此代码

04-12 09:39:59.980:  xxxxxxxxxxxxxxxxxxxxxx
04-12 09:39:59.980: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
04-12 09:39:59.980:  <html><head>
04-12 09:39:59.980:  <title>403 Forbidden</title>
04-12 09:39:59.980:  </head><body>
04-12 09:39:59.980:  <h1>Forbidden</h1>
04-12 09:39:59.980:  <p>**You don't have permission to access /younes_project/younesservices.php**
04-12 09:39:59.980:  on this server.</p>
04-12 09:39:59.980:  </body></html>
04-12 09:39:59.980: xxxxxxxxxxxxxxxxxxxxxx
请问这种情况有什么问题 :):):)

1 个答案:

答案 0 :(得分:0)

这对您的代码没有问题。这是服务器端脚本(PHP)或文件访问权限的问题。服务器正在向您发送错误页面而不是json响应。您可以联系您的PHP开发人员,要求他更改文件访问权限文件/younes_project/younesservices.php。