尝试将html字符串转换为JSONObject时发生JSONException

乔卡·多奇(Joca Doci)

我知道很多人都遇到同样的问题,但是任何答案都可以帮助我。所有人都把我弄糊涂了。
我正在尝试在Android上进行登录/注册。问题显示如下。

W/System.err: org.json.JSONException: Value <br><table of type java.lang.String cannot be converted to JSONObject 
W/System.err:     at org.json.JSON.typeMismatch(JSON.java:111)
W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:160)
W/System.err:     at org.json.JSONObject.<init>(JSONObject.java:173)
...

这是我的代码。

final Button bRegister = (Button) findViewById(R.id.rButton);

    bRegister.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            final String name = etName.getText().toString();
            final String username = etUsername.getText().toString();
            final String password = etPassword.getText().toString();

            Response.Listener<String> responseListener = new Response.Listener<String>() {
                @Override
                public void onResponse(String response) {
                    try {
                        JSONObject jsonResponse = new JSONObject(response);
                        boolean success = jsonResponse.getBoolean("success");
                        if (success) {
                            Intent intent = new Intent(RegisterActivity.this, LoginActivity.class);
                            RegisterActivity.this.startActivity(intent);
                        } else {
                            AlertDialog.Builder builder = new AlertDialog.Builder(RegisterActivity.this);
                            builder.setMessage("Register Failed")
                                    .setNegativeButton("Retry", null)
                                    .create()
                                    .show();
                        }
                    } catch (JSONException e) {
                        e.printStackTrace();
                    }
                }
            };

            RegisterRequest registerRequest = new RegisterRequest(name, username, password, responseListener);
            RequestQueue queue = Volley.newRequestQueue(RegisterActivity.this);
            queue.add(registerRequest);
        }
    });
}

}

当然是php之一。

<?php
$con = mysqli_connect("host", "user", "password", "database");


$name = $_POST["name"];
$username = $_POST["username"];
$password = $_POST["password"];
$statement = mysqli_prepare($con, "INSERT INTO user (name, username, password) VALUES (?, ?, ?)");
mysqli_stmt_bind_param($statement, "sss", $name, $username, $password);
mysqli_stmt_execute($statement);

$response = array();
$response["success"] = true;  

echo json_encode($response); 

在此先感谢您的帮助,对于造成的麻烦我们深表歉意。

乔卡·多奇(Joca Doci)

多亏有一个帮助我的人,我可以解决我的问题,所有乞讨我正在使用的Web主机(000webhost)当您在其中运行php文件时,我都不是什么问题,我将Web主机更改为hostiger,我在第二行中更改了一些我的php代码。

$ con = mysqli_connect(“本地主机”,“用户”,“密码”,“数据库”);

在主机中,我留下“ localhost”,而用户名,密码和数据库是Web主机页面提供给您的信息。有了这个,并在请求代码中更改了我的域,我的应用程序运行完美。感谢所有花时间阅读和回答本文的人。

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

将JSONObject转换为字符串

尝试将字符串数组转换为具有给定混合dtypes的数组时发生ValueError

将JSONObject转换为List <JSONObject>或将字符串转换为List <JSONObject>

无法将字符串转换为JSONObject

如何将字符串转换为JSONObject?

Android将字符串转换为JSONObject

如何将JsonObject转换为JSON字符串?

将json格式的字符串转换为jsonObject Android

如何将日期 JsonObject 转换为字符串?

Swift:在将html字符串转换为属性字符串时添加空白

尝试使用 .substr 将字符串转换为字符

将数组强制转换为字符串枚举器时发生运行时错误

将字符串转换为日期时间时,毫秒精度正在发生变化

将int转换为字符串时,实际上发生了什么?

JSONObject转换为Android字符串

尝试将形式为“ -0.06”的字符串转换为数字时,获取NA

在Ruby on Rails中尝试将字符串转换为JSON对象时感到困惑

尝试将符号包装器对象明确转换为字符串时出错

尝试将字符串转换为类别时出现关键错误

尝试将输入字符串转换为float时引发意外异常

尝试使用Integer.parseInt()将字符串转换为整数时出错

尝试应用身份验证中间件时将数组转换为字符串

尝试将字符串转换为值

尝试将方法从字符串转换为整数

尝试将字符串转换为数字返回 NaN

尝试将字符串数组转换为日期

尝试将字符串转换为实例变量

Elm尝试将字符串转换为选项类型

尝试将SQL查询的值转换为字符串