PHP- Decode JSON

前端 未结 3 1326
陌清茗
陌清茗 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:38

    If input is in array format then also you can use the same function json_decode. You just need to apply loop for result.

    json = '{

    "a1":{ "field1":"name1", "field2":age1, "field3":"country1" },

    "a2":{ "field1":"name2", "field2":age2, "field3":"country2" },

    "a3":{ "field1":"name3", "field2":age3, "field3":"country3" } }';

    $Array = json_decode($json, true);

    foreach ($Array as $key => $value)
    {

        echo " $key ";
    
        foreach ($value as $k => $val)    
        {
            echo "$k | $val 
    "; }

    }

提交回复
热议问题