当我将 json 编码值从 PHP 传递到 Javascript 并仅在控制台记录它时,它返回给我:
{"id":"4","username":"muzikant346","coins":"675","avatar1":"1","avatar2":"0","avatar3":"0","avatar4":"0","avatar_selected":"0"}
这是一个字符串,当我想用 Javascript 解析它时,它返回一个错误:
eUncaught SyntaxError: Unexpected token in JSON at position 0
at JSON.parse (<anonymous>)
at Object.success (welcome.js:11)
at c (jquery-3.4.1.min.js:2)
at Object.fireWith [as resolveWith] (jquery-3.4.1.min.js:2)
at l (jquery-3.4.1.min.js:2)
at XMLHttpRequest.<anonymous> (jquery-3.4.1.min.js:2)
我不明白为什么 javascript 不能解析这个。
有我的 PHP(从数据库中获取)代码:
$sql = "SELECT * FROM serbian_values WHERE username = '$username'";
$result = mysqli_query($link, $sql);
if($result){
while($row = mysqli_fetch_assoc($result)){
$value[] = $row;
}
echo json_encode($value[0]);
}
暮色呼如
喵喵时光机
繁华开满天机