PHP- Decode JSON

前端 未结 3 1325
陌清茗
陌清茗 2020-11-30 16:13

I have the following script to get search results from an API and then slice the array and dump it, I am having trouble decoding the JSON into an array, it returns Arr

3条回答
  •  盖世英雄少女心
    2020-11-30 16:37

    Try json_decode

    $array = json_decode($data, true);
    

    Then you'll get an array instead of an object.

    Example #1 json_decode() examples

    
    

    The above example will output:

    object(stdClass)#1 (5) {
        ["a"] => int(1)
        ["b"] => int(2)
        ["c"] => int(3)
        ["d"] => int(4)
        ["e"] => int(5)
    }
    
    array(5) {
        ["a"] => int(1)
        ["b"] => int(2)
        ["c"] => int(3)
        ["d"] => int(4)
        ["e"] => int(5)
    }
    

提交回复
热议问题