如何从php中的json响应数组中获取值?

时间:2016-01-30 09:52:44

标签: php arrays json

我有一个json响应,如下面的

{"name":['abc','def','ghi','jkl']}

如何在php中提取每个名称?

expected out put :

abc
def
ghi
jkl

2 个答案:

答案 0 :(得分:1)

使用json_decode

见此链接
function.json-decode.php

   $jsons=array('name'=>array("abc","def","ghi","jkl"));  
   foreach($jsons as $json ){
        foreach($json as $val){
            echo $val  .'<br>';
        }
    }

答案 1 :(得分:0)

像这样使用

<?php
 $var = '{"name":["abc","xyz"]}';// here will be your response
  $arr = json_decode($var);
 foreach($arr->name as  $key=>$value)
 echo $value."<br/>";
 ?>