【问题标题】:parse json string to array将json字符串解析为数组
【发布时间】:2013-08-10 07:43:51
【问题描述】:

我无法解析下面给出的这个 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.

谢谢

【问题讨论】:

  • 您的字符串不是有效的 JSON。
  • 顺便说一句,请改用json_decode($json_string, TRUE);
  • 它正在工作,我可以知道第二个参数 true 是什么意思吗?
  • @VeNaToR 它返回一个array 而不是stdClass 对象。

标签: php codeigniter json


【解决方案1】:

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

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

试试上面的东西..

【讨论】:

    【解决方案2】:

    第一个对象没有键。 JSON 中不允许出现两个连续的 {{。将第一个 { 替换为 [。当然最后一个结束 } 用 ] 使它成为一个有效的数组。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-23
      • 2018-06-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多