Php android中的Json错误

Php android中的Json错误,php,android,json,Php,Android,Json,我有一个android移动应用程序,它将使用一个名为“login.php”的php文件连接到一个包含用户名和密码的数据库,php文件的结果是JSON格式,它看起来是这样的:{“username”:“mounzer”,“password”:“yaghi”} 对于移动应用程序,代码如下: public void onClick(View v) { // TODO Auto-generated method stub StrictMode.ThreadPolicy polic

我有一个android移动应用程序,它将使用一个名为“
login.php
”的php文件连接到一个包含用户名和密码的数据库,php文件的结果是
JSON
格式,它看起来是这样的:
{“username”:“mounzer”,“password”:“yaghi”}
对于移动应用程序,代码如下:

public void onClick(View v) { 
    // TODO Auto-generated method stub    
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);         
    httpclient = new DefaultHttpClient();
    // defaultHttpClient
    httpclient = new DefaultHttpClient();
    httppost = new HttpPost("http://192.168.1.38/mobileappd/Login.php");

    username=user.getText().toString();
    password=pass.getText().toString();

    try {
        nameValuePairs = new ArrayList<NameValuePair>();
        nameValuePairs.add(new BasicNameValuePair("username",username));
        nameValuePairs.add(new BasicNameValuePair("password",username));

        httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        response = httpclient.execute(httppost);

        if(response.getStatusLine().getStatusCode()==200) {
            entity=response.getEntity();    

            if(entity !=null) {
                InputStream instream=entity.getContent();
                JSONObject jsonResponse = new JSONObject(convertStreamToString(instream));
                String retUser=jsonResponse.getString("username");
                String retPass=jsonResponse.getString("password");

                if(username.equals(retUser) && password.equals(retPass)) {

                    SharedPreferences sp=getSharedPreferences("logindetails",0);
                    SharedPreferences.Editor spedit=sp.edit();
                    spedit.putString("user",username);
                    spedit.putString("pass", password);
                    spedit.commit();

                    Toast.makeText(getBaseContext(), "Succesfully connected",Toast.LENGTH_LONG).show();
                }
            }
        }
    } catch(Exception e) {  
        e.printStackTrace();
        Toast.makeText(getBaseContext(), e.toString(), Toast.LENGTH_LONG).show();
    }
}
public void onClick(视图v){
//TODO自动生成的方法存根
StrictMode.ThreadPolicy policy=新建StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(策略);
httpclient=新的DefaultHttpClient();
//defaultHttpClient
httpclient=新的DefaultHttpClient();
httppost=新的httppost(“http://192.168.1.38/mobileappd/Login.php");
username=user.getText().toString();
password=pass.getText().toString();
试一试{
nameValuePairs=新的ArrayList();
添加(新的BasicNameValuePair(“用户名”,username));
添加(新的BasicNameValuePair(“密码”,用户名));
setEntity(新的UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
if(response.getStatusLine().getStatusCode()==200){
entity=response.getEntity();
如果(实体!=null){
InputStream instream=entity.getContent();
JSONObject jsonResponse=新的JSONObject(convertStreamToString(instream));
String retUser=jsonResponse.getString(“用户名”);
String retPass=jsonResponse.getString(“密码”);
if(username.equals(retUser)和password.equals(retPass)){
SharedReferences sp=GetSharedReferences(“登录详细信息”,0);
SharedReferences.Editor spedit=sp.edit();
spedit.putString(“用户”,用户名);
spedit.putString(“pass”,密码);
提交();
Toast.makeText(getBaseContext(),“成功连接”,Toast.LENGTH_LONG.show();
}
}
}
}捕获(例外e){
e、 printStackTrace();
Toast.makeText(getBaseContext(),e.toString(),Toast.LENGTH_LONG).show();
}
}
它给了我以下的错误:
org.json.JSONException:java.lang.string类型的值DOCTYPE无法转换为JSONobject
”有人能告诉我代码中的错误在哪里。

这里的错误消息说

Value `<!DOCTYPE` of type java.lang.String cannot be converted to JSONObject

Value`检查从您调用的链接返回的结果,我认为它返回的是html页面,因为它说“Value DOCTYPE不能转换为JSONOBject”。因此,请检查您通过调用该链接得到的响应

您可以提交更多您收到的错误日志吗