";nn”;添加到JSONObject之前


"nn" added before JSONObject

在我的应用程序中,我用JSON发送一个HTTP请求,以从MYSQL数据库获取登录详细信息。

就在最近,我一直在尝试让数据库和phpapi运行UTF-8编码。

然而,当我现在尝试登录时,我得到了这个错误:

07-18 14:06:41.507: E/JSON(32162): nn{"tag":"login1","success":1,"error":0,"User":{"id":"1","email":"admin@fleetcoordinator.se","fullname":"Administrator","password":"admin","userRole":"Admin","userName":"admin"}}n
07-18 14:06:41.512: E/JSON Parser(32162): Error parsing data org.json.JSONException: Value nn of type java.lang.String cannot be converted to JSONObject

很明显,是JSON数据之前的"nn"导致应用程序崩溃,但这是从哪里来的?

Php-api:

// response Array
$response = array("tag" => $tag, "success" => 0, "error" => 0);

    else if ($tag == "login1"){
    //request type is login1, for fltcoor db
    $username = $_POST['username'];
    $password = $_POST['password'];
    //check for user, fill it into user array
    $user = $db1->getLoginDetails($username, $password);
    if($user != false){
        //user found
        //put user details into JSON response array
        $response["success"] = 1;
        $response["User"]["id"]         = $user["id"];
        $response["User"]["email"]      = $user["email"];
        $response["User"]["fullname"]   = $user["fullname"];
        $response["User"]["password"]   = $user["password"];
        $response["User"]["userRole"]   = $user["userRole"];
        $response["User"]["userName"]   = $user["username"];
        //echo json response
        echo json_encode($response);
    } else {
        //user not found, echo json with error = 1(user not found)
        $response["error"] = 1;
        $response["error_msg"] = "Wrong username or password";
        echo json_encode($response);
    }       

有人能看到这些"nn"是从哪里来的吗。如果您需要更多信息来跟踪问题,请告诉我。

这个问题是由我的字符串生成器中的一个missin"''"引起的。

        try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(
                is, "UTF-8"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "'n");
        sb.append(line + "'n"); was sb.append(line + "n");, the ' was missing and adding 2 "nn" before the JSONObject.