如何将 JSON 对象插入 MySQL 数据库


How i can insert a JSON object into MySQL database?

嗨,我一直在为这个问题而努力,但我什么也没找到.

问题很简单:

如何将 json 对象插入 mysql databse 以便稍后检索它,json 对象如下:

$CHE=mysqli_real_escape_string($conexio,$_POST['checkE']);//json object 1
$CHT=mysqli_real_escape_string($conexio,$_POST['checkT']);//json object 2
$CHF=mysqli_real_escape_string($conexio,$_POST['checkF']);//json object 3
$CHD=mysqli_real_escape_string($conexio,$_POST['checkD']);//json object 4
$CHA=mysqli_real_escape_string($conexio,$_POST['checkA']);//json object 5

//$query_it=mysqli_query($conexio," INSERT INTO menu values('".$personal_name."','".utf8_decode($CHE)."','".utf8_decode($CHT)."','".utf8_decode($CHF)."','".utf8_decode($CHD)."','".utf8_decode($CHA)."')");    

一旦代码运行完毕,我们可以看到数据进入 MySQL 表,如下所示:

{"menuE":{"Introducción":{},"Visualización":{}}}

但不是例如如下(即,带斜杠):

"{'"title'":'"Sachin vs shoaib akhtar and company..Unseen (BAAP BAAP HI HOTA HAI ) ....flv'",'"titleEsc'":'"Sachin vs shoaib akhtar and company..Unseen (BAAP BAAP HI HOTA HAI ) ....flv'",'"url'":'"http://www.youtube.com/watch?v=WOJlDpoL7tw'",'"pageUrl'":'"http://www.youtube.com/watch?v=WOJlDpoL7tw'",'"cannonicalUrl'":'"www.youtube.com'",'"description'":'"Sachin hitting cluless shoaib akhtar and company everywhere in ground..This is one f many innings where shoaib akhtar was brutually assaulted by sachin tendu...'",'"descriptionEsc'":'"Sachin hitting cluless shoaib akhtar and company everywhere in ground..This is one f many innings where shoaib akhtar was brutually assaulted by sachin tendu...'",'"images'":'"http://i2.ytimg.com/vi/WOJlDpoL7tw/hqdefault.jpg'",'"video'":'"yes'",'"videoIframe'":'"<iframe id='''"20131122120255WOJlDpoL7tw'''" style='''"display: none; margin-bottom: 5px;'''" width='''"499'''" height='''"368'''" src='''"http://www.youtube.com/embed/WOJlDpoL7tw'''" frameborder='''"0'''" allowfullscreen></iframe>'"}";

因为如果它与上面的结构一起保存,我们可以执行以下操作检索信息:

$array=json_decode($objstring,true);
//var_dump($array);

foreach($array  as $titol=>$llista){
    echo "TITOL: ".$titol."   LLISTA:  ".$llista;;
    echo"<br>";
    }

那么我如何保存 JSON 对象呢?

谢谢

我会尝试用json_encode()将它们串起来

$CHE=mysqli_real_escape_string($conexio,json_encode($_POST['checkE']));//json object 1