你好,我有php輸出json編碼的pdo數組,並給出了\\\
字符輸出,我想delete
他們。Php json_encode數組輸出錯誤
我的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\"}"]
我想刪除\
字符。
謝謝
這實際上是一個有效的JavaScript字符串,因爲......等等什麼? –
@PraveenKumar我將使用輸出爲快速的應用程序,並不採取值給出錯誤時有\ – SwiftDeveloper
你不能JSON編碼的JSON數組... ... LoL。 –