$var ="
{
key : {
key_deep : val\{ue /* should be "val{ue" as { is escaped */
} ,
key2 : value
}
";
print_r(preg_split('//',$var));
// array(
// array(
// 'key'=> array(
// 'key_deep'=> 'val{ue'
// )
// ),
// array('key2'=>'value')
// );是否有正则表达式在php中使用preg_split将其拆分?
基本上,我需要与json_decode()相同的内容,但是不需要上的引号,、value和key都需要,唯一转义的是四个字符\{ \, \} \:
发布于 2011-05-23 16:42:11
考虑到这里可能出现的任意嵌套,您可能希望查看解析器而不是正则表达式。
尝试:
ParserGenerator/重定向
或
http://www.hwaci.com/sw/lemon/
或
http://www.google.com/search?sourceid=chrome&ie=UTF-8&q=php+parser+generator
发布于 2011-05-23 16:11:39
首先,json是不正确的,它会在json_decode上抛出一个错误。
阅读json 这里的规范
json的一个正确实现是:
$var ='
{
"key" : {
key_deep : "val\{ue"
} ,
"key2" : "value"
}
';另外,json_decode永远不会产生Array,除非添加true参数,否则会产生object(stdClass)
https://stackoverflow.com/questions/6099891
复制相似问题