我在 mysql 单元中得到了以下 json 代码:
{
"0ba9f1d1-787c-4d8e-a820-0c973bbd20fb": {
"0": {
"value": "Alex"
}
},
"9a7df867-1c25-4e15-b0dd-1d20031c31fb": {
"0": {
"value": "Άλέξανδρος Γιόου"
}
},
"659d5d3d-ac12-4f17-91c0-334fbd4f3538": {
"option": {
"0": "0",
"1": "0"
},
"select": "1"
}
}
我想更新 php.ini 中的一些值。我尝试使用以下代码,但得到了一些意想不到的结果。
$check = mysql_query("SELECT `elements` FROM `test_zoo_item` WHERE `id` = 34839");
$decodedelements = json_decode($elements, true);
$decodedelements['0ba9f1d1-787c-4d8e-a820-0c973bbd20fb'][0]['value'] = "Test";
$decodedelements['9a7df867-1c25-4e15-b0dd-1d20031c31fb'][0]['value'] = "Γιώργος";
$decodedelements['659d5d3d-ac12-4f17-91c0-334fbd4f3538']['option'][0] = "3";
$newelements = json_encode($decodedelements);
mysql_query("UPDATE `test_zoo_item` SET `elements`='$newelements' WHERE `id`=34839");
我更新的单元格是:
{
"0ba9f1d1-787c-4d8e-a820-0c973bbd20fb": [{
"value": "Alex"
}],
"9a7df867-1c25-4e15-b0dd-1d20031c31fb": [{
"value": "u00ce...fu0082"
}],
"659d5d3d-ac12-4f17-91c0-334fbd4f3538": {
"option": ["0", "0"],
"select": "1"
}
}
是否可以提供帮助,以便我可以解决以下问题?
"0": {"value": "Alex"}
变成[{"value": "Alex"}]
"value": "Άλέξανδρος Γιόου"
变成"value": "u00c....cfu0082"
"option": {"0": "0","1": "0"}
变成"option": ["0", "0"]