原始: {"db":"[{"0":"9","id":"9"},{"0":"9","id":"9"},]"}我想要: {"db":[{"0":"9","id":"9"},{"0":"9","id":"9"}]}怎么替换字符???
2 回答
桃花长相依
TA贡献1860条经验 获得超8个赞
可以用正则
$jsonStr = '{"db":"[{"0":"9","id":"9"},{"0":"9","id":"9"},]"}' ; $jsonStr = preg_replace( '/[\'"](\[.*?\])[\'"]/iU' , '$1' , $jsonStr ); // 去除json串中,数组外的引号,将形如"[{...}]"替换成[{...}] $jsonStr = preg_replace( '/,\s*\]/' , ']' , $jsonStr ); // 去除json串中多余的逗号 |
字符串替换:
$jsonStr = str_replace ( '"[' , '[' , $jsonStr ); $jsonStr = str_replace ( ',]"' , ']' , $jsonStr ); |
皈依舞
TA贡献1851条经验 获得超3个赞
$raw = '{"db":"[{"0":"9","id":"9"},{"0":"9","id":"9"},]"}';
$obj = @json_decode($raw, TRUE);
$obj['db'] = @json_decode($obj['db'], TRUE);
$i_want = @json_encode($obj);
- 2 回答
- 0 关注
- 172 浏览
添加回答
举报
0/150
提交
取消