我在java(android)中有以下代码:
String image = null;
ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
nameValuePairs.add(new BasicNameValuePair("pic_image",image));
TextView tv1 = (TextView) findViewById(R.id.image);
DefaultHttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.carprotectionsystem.webuda.com/image.php");
try {
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse response = httpclient.execute(httppost);
if(response.getStatusLine().getStatusCode()==200)
{
HttpEntity entity = response.getEntity();
if(entity !=null)
{
InputStream instream=entity.getContent();
JSONObject jsonResponse = null;
try {
jsonResponse = new JSONObject(convertStreamToString(instream));
} catch (Exception e) {
}
try {
image =jsonResponse.getString("pic_image");
} catch (Exception e) {
}
tv1.setText(image);
}
}
}
catch (Exception e)
{
Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_SHORT).show();
} }
并且 php 脚本在浏览器中给了我这个响应:{"pic_image":"a"}
我想在 android 的文本视图中显示“a”,但出现此错误:
org.json.JSONexception : value DOCTYPE of type java.lang.string cannot be converted to JSONObject
任何帮助?