将json字符串解析为数组

时间:2013-08-10 07:43:51

标签: php codeigniter json

我无法解析下面给出的这个json字符串,任何人都建议一些不错的选择:

$json_string = '{{"name":"ff","phone":344543},{"name":"sdf","phone":344543},       {"name":"sfsd","phone":344543}}';

i have tried json_decode($json_string); but not working. I need to parse this string and retrieve the coontants as normal array. please help.

由于

2 个答案:

答案 0 :(得分:2)

您的JSON字符串不正确, 正确的方法:

$json_string = '[{"name":"ff","phone":344543},{"name":"sdf","phone":344543},{"name":"sfsd","phone":344543}]';
print_r(json_decode($json_string));

尝试上面的事情..

答案 1 :(得分:0)

第一个对象没有密钥。连续两次{{不允许使用JSON。替换第一个{与[。当然最后一个关闭}用一个]来使它成为一个有效的数组。