Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 发送数据时发生JSON异常_Android_Json_Apache - Fatal编程技术网

Android 发送数据时发生JSON异常

Android 发送数据时发生JSON异常,android,json,apache,Android,Json,Apache,错误: 日志会告诉您原因: Value <html><head><title>Apache of type java.lang.String cannot be converted to JSONObject JSONException:Value由于某种原因,您没有得到JSON,您正在到达一个HTML页面,那么我如何解决这个问题呢?至少您应该找到一种方法来记录响应,然后再尝试解析itI。我尝试了这种方法,并且将要进行的响应打印为org.apache.htt

错误:


日志会告诉您原因:

Value <html><head><title>Apache of type java.lang.String cannot be converted to JSONObject

JSONException:Value由于某种原因,您没有得到JSON,您正在到达一个HTML页面,那么我如何解决这个问题呢?至少您应该找到一种方法来记录响应,然后再尝试解析itI。我尝试了这种方法,并且将要进行的响应打印为org.apache.http.message。BasicHttpResponse@414dd928thats不是,,你需要看看你的应用程序是否可以访问url,这可能是一个404未找到页面,因为你的响应包含html。你应该在你的浏览器中运行脚本或者其他一些东西,以确保它是正确的。我该怎么做呢;它已经打印了html标签。。。如何将其转换为JSON字符串您有返回的完整字符串吗?
public void handleResponse(String response) 
{     
    EditText edFirstName = (EditText) findViewById(R.id.first_name);
    EditText edLastName = (EditText) findViewById(R.id.last_name);
    EditText edEmail = (EditText) findViewById(R.id.email);

    String firstName=edFirstName.getText().toString();
    String lastName=edLastName.getText().toString();
    String email=edEmail.getText().toString();

    edFirstName.setText("");
    edLastName.setText("");
    edEmail.setText("");

    try 
    {

        JSONObject jso = new JSONObject(response.toString());

        String jfirstName = jso.getString(firstName);
        String jlastName = jso.getString(lastName);
        String jemail = jso.getString(email);

        edFirstName.setText(jfirstName);
        edLastName.setText(jlastName);
        edEmail.setText(jemail);                      
    } catch (Exception e) 
    {
        Log.e(TAG, e.getLocalizedMessage(), e);
    }    
}
Value <html><head><title>Apache of type java.lang.String cannot be converted to JSONObject
{
    "glossary": {
        "title": "example glossary",
        "GlossDiv": {
            "title": "S",
        }
    }
}