你好我的php mysql pdo数组带有输出json编码,并在输出中给出\\\
个字符,我想delete
个。
我的PHP代码
$stmt2 = $this->conn->prepare("SELECT ID,clientName FROM Clients WHERE userID='$userID' OR mainAccountID='$mainAccountID' ORDER BY ID DESC");
$stmt2->execute();
$result = $stmt2 -> fetchAll();
foreach( $result as $userRow2 ) {
$private_list[] = '{"name":"'.$userRow2['clientName'].'","ID":"'.$userRow2['ID'].'"}';
}
echo json_encode($private_list);
并提供输出
["{\"name\":\"zz\",\"ID\":\"312\"}","{\"name\":\"jv\",\"ID\":\"311\"}","{\"name\":\"fff2222\",\"ID\":\"309\"}","{\"name\":\"ffff\",\"ID\":\"308\"}","{\"name\":\"v\",\"ID\":\"288\"}","{\"name\":\"t\",\"ID\":\"286\"}","{\"name\":\"s\",\"ID\":\"285\"}","{\"name\":\"r\",\"ID\":\"284\"}","{\"name\":\"p\",\"ID\":\"283\"}","{\"name\":\"o\",\"ID\":\"282\"}","{\"name\":\"n\",\"ID\":\"281\"}","{\"name\":\"m\",\"ID\":\"280\"}","{\"name\":\"l\",\"ID\":\"279\"}","{\"name\":\"k\",\"ID\":\"278\"}","{\"name\":\"j\",\"ID\":\"277\"}","{\"name\":\"i\",\"ID\":\"276\"}","{\"name\":\"h\",\"ID\":\"275\"}","{\"name\":\"g\",\"ID\":\"274\"}","{\"name\":\"f\",\"ID\":\"273\"}","{\"name\":\"e\",\"ID\":\"272\"}","{\"name\":\"d\",\"ID\":\"271\"}","{\"name\":\"c\",\"ID\":\"270\"}","{\"name\":\"b\",\"ID\":\"269\"}","{\"name\":\"a\",\"ID\":\"268\"}"]
我想删除\
字符。
由于
答案 0 :(得分:3)
更改您的代码以包含一个表单。您正在混合使用JavaScript和PHP。所以,这样做:
$private_list = array();
$private_list[] = array(
"name" => $userRow2['clientName'],
"ID" => $userRow2['ID']
);