【发布时间】:2019-10-04 08:48:45
【问题描述】:
我正在尝试对行选项进行 JSON 解码,并使用其余数据对其进行编码。但它只给了我选项行但是。如果我不解码它,请在选项行中用反斜杠给我这个。
[{"ID":"4","AppID":"1","Question":"test2","Type":"Radios","OrderNumber":"2","Options":" {\“1号\”: \"Yes\", \"Number2\": \"No\"}"}]
//open connection to mysql db
$connection = mysqli_connect($dbhost,$dbuser,$dbpass,$dbdata) or die("Error " . mysqli_error($connection));
//fetch table rows from mysql db
$sql = "select * from App_Questions";
$result = mysqli_query($connection, $sql) or die("Error in Selecting " . mysqli_error($connection));
//create an array
$emparray = array();
while ($row =mysqli_fetch_assoc($result)) {
if ($row["Options"]){
$str = json_decode($row["Options"]);
$emparray = $str;
}else{
$emparray[] = $row;
}
}
echo json_encode($emparray);
【问题讨论】:
-
If I don't decode,你为什么不解码 JSON 字符串?数据库中有什么,你有什么,你想要什么? ...以后可能会问,如果数据被转义存储,你是如何写入数据的? -
你当前代码的输出是什么?
标签: php mysql arrays json mysqli