我正试图将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
,如果这有帮助的话。
我只是错误地调用了php:/