RT 1013: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1", 1014: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1",
1015: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1",
...............................如何让所有的数字都加双引号,这些数字都是随机的
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1", 1014: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1",
1015: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1",
...............................如何让所有的数字都加双引号,这些数字都是随机的
的确有用
不过我只需要
1013: {}1014{}这些key加引号,请问一下应该如何做?
<?php
$json = <<<TXT
{
1013: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1"
},
1014: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1"
},
1015: {
"app_type": "2",
"device_type": "1",
"area_id": "1",
"is_open": "1"
}}
TXT; if(preg_match('/\w:/', $json)){
$json = preg_replace('/([1013|1014]+):/is', '"$1":', $json); // 什么数字,你在这里定义就可以了。
} echo $json;?>