1

我正在尝试将我的 php 文件中的字符串返回到我的 android 应用程序。php 文件不是 json 格式。jsonobject 只是返回错误07-28 20:10:56.538: W/System.err(2936): org.json.JSONException: Value <!DOCTYPE of type java.lang.String cannot be converted to JSONObject我也尝试过 SAXParser,但我知道这仅适用于 xml 文件。当我使用StringBuilder这样的

public static String iStream_to_String(InputStream is1) {
    BufferedReader rd = new BufferedReader(new InputStreamReader(is1), 8192);
    String line;
    StringBuilder sb = new StringBuilder();
    String longitudecord = "";
    try {
        while ((line = rd.readLine()) != null) {
            sb.append(line+"\n");

        }
//          rd.close();

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



    String contentOfMyInputStream = sb.toString();
    return contentOfMyInputStream;
}

我得到一个很像这样<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 的响应,我想要得到的响应是一个返回给定错误文件的简单字符串。有没有办法在没有 json 的情况下完成如此简单的任务?

我也想添加 php 的文件类型application/x-httpd-php是否有帮助。

4

1 回答 1

0

我只是错误地调用了php:/

于 2012-08-22T18:47:59.220 回答