如何解码json对象数组 [英] How to decode an array of json objects

查看:83
本文介绍了如何解码json对象数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个像这样的json对象数组:

I have an array of json objects like so:

[{"a":"b"},{"c":"d"},{"e":"f"}]

将其转换为php数组的最佳方法是什么?

What is the best way to turn this into a php array?

json_decode 将不处理数组部分,并为此字符串返回NULL.

推荐答案

json_decode()可以工作.第二个参数将结果转换为数组:

json_decode() does so work. The second param turns the result in to an array:

var_dump(json_decode('[{"a":"b"},{"c":"d"},{"e":"f"}]', true));

// gives

array(3) {
  [0]=>
  array(1) {
    ["a"]=>
    string(1) "b"
  }
  [1]=>
  array(1) {
    ["c"]=>
    string(1) "d"
  }
  [2]=>
  array(1) {
    ["e"]=>
    string(1) "f"
  }
}

这篇关于如何解码json对象数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆