将字符串转换为JSON

时间:2014-05-14 07:11:11

标签: php json yii casting

有没有办法让PHPstring视为JSON? 我有一个string,当然是JSON格式,我想对它执行操作,就像它是一个数组一样。但是我不想使用CJSON::decode,因为它需要很长时间,有办法吗? 字符串示例:

{"myArray":[{"key1":"val1","key2":"val2","key3":"val3","key4":"val4"},
{"key1":"val2_1","key2":"val2_2","key3":"val2_3","key4":"val2_4"}]}

2 个答案:

答案 0 :(得分:0)

json_decode()怎么样?

我认为没有比那更快的

$string = '{"myArray":[{"key1":"val1","key2":"val2","key3":"val3","key4":"val4"},    {"key1":"val2_1","key2":"val2_2","key3":"val2_3","key4":"val2_4"}]}';
$array = json_decode($string);

答案 1 :(得分:0)

不确定CJSON :: decode是什么,但您必须解码字符串,以便您可以使用内置函数json_decode($str);