How to decode an array of json objects

前端 未结 2 372
无人共我
无人共我 2021-01-13 04:29

I have an array of json objects like so:

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

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

2条回答
  •  一整个雨季
    2021-01-13 04:45

    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"
      }
    }
    

提交回复
热议问题