如何將此json對象拆分爲3部分id
awnser
和type
?通過PHP將json對象的列拆分爲更多列
[{"id":"26","answer":[{"option":"3","text":"HIGH"}],"type":"a"},
{"id":"30","answer":[{"option":"3","text":"LOW"}],"type":"b"},
{"id":"31","answer":[{"option":"3","text":"LOW"}],"type":"c"}]
和DB名稱:array
表名:user_survey_start
JSON列名:survey_answers
,這是我的代碼:
<?php
$con=mysqli_connect("localhost","root","","arrayy");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$sql="SELECT `survey_answers` FROM `user_survey_start`";
if ($result=mysqli_query($con,$sql)){
while ($row = mysqli_fetch_row($result)){
}
mysqli_close($con);
?>
分至3 JSON對象? '{「id」:「26」}''{answer「:[{」option「:」3「,」text「:」HIGH「}]}''{」type「:」a「}' – mith
我可以有這樣的東西嗎? '26,30,31'和'High,low.low'和'a,b,c' //這是下一行之後的一行 –