如何获得价值

时间:2019-05-27 10:40:42

标签: php codeigniter

我有一个问题和这样的代码。

{"resultcode":"0","message":"Success","description":[{"STORECODE":"F3YQ","STORENAME":"BUNGUR BESAR 30B","ADDRESS":"JL.BUNGUR BESAR NO.30BGUNUNG SAHARI SELATAN","PHONE":"021","POSTALCODE":"10610","OPHOURS":"EVERYDAY (07.00-22.00)","LATITUDE":"-6.1605556","LONGITUDE":"106.8391667","DCCODE":"G137","DCNAME":"JKT2"}]}

我很难获得价值。 我需要这样的值:

成功 F3YQ 10610 JKT2

4 个答案:

答案 0 :(得分:1)

这很简单

$a = json_decode($yourArr, true); // last parameter to convert it into array
echo $a['message'].' '.$a['description'][0]['STORECODE'].' '.$a['description'][0]['POSTALCODE'].' '.$a['description'][0]['DCNAME'];

答案 1 :(得分:0)

假设数据存储在变量中

$data = {"resultcode":"0","message":"Success","description":[{"STORECODE":"F3YQ","STORENAME":"BUNGUR BESAR 30B","ADDRESS":"JL.BUNGUR BESAR NO.30BGUNUNG SAHARI SELATAN","PHONE":"021","POSTALCODE":"10610","OPHOURS":"EVERYDAY (07.00-22.00)","LATITUDE":"-6.1605556","LONGITUDE":"106.8391667","DCCODE":"G137","DCNAME":"JKT2"}]};

$values = json_decode($data);

echo $values['description'][0]['STORECODE'];

答案 2 :(得分:0)

  

您需要使用[async_uuid(…)]来将json_decode()转换为json,然后您才能执行所需操作,请检查以下代码

array

输出:

$str_json = '{"resultcode":"0","message":"Success","description":[{"STORECODE":"F3YQ","STORENAME":"BUNGUR BESAR 30B","ADDRESS":"JL.BUNGUR BESAR NO.30BGUNUNG SAHARI SELATAN","PHONE":"021","POSTALCODE":"10610","OPHOURS":"EVERYDAY (07.00-22.00)","LATITUDE":"-6.1605556","LONGITUDE":"106.8391667","DCCODE":"G137","DCNAME":"JKT2"}]}';
echo'<pre>';print_r(json_decode($str_json,true));
$str_array = json_decode($str_json,true);
echo $str_array['message'].' '.$str_array['description'][0]['STORECODE'].' '.$str_array['description'][0]['POSTALCODE'].' '.$str_array['description'][0]['DCNAME'];die;

答案 3 :(得分:0)

Demo Link

您可以使用 json_decode php函数

获取数据
$nvjsonresponse = '{"resultcode":"0","message":"Success","description":[{"STORECODE":"F3YQ","STORENAME":"BUNGUR BESAR 30B","ADDRESS":"JL.BUNGUR BESAR NO.30BGUNUNG SAHARI SELATAN","PHONE":"021","POSTALCODE":"10610","OPHOURS":"EVERYDAY (07.00-22.00)","LATITUDE":"-6.1605556","LONGITUDE":"106.8391667","DCCODE":"G137","DCNAME":"JKT2"}]};'
$nvarrayval = json_decode($nvjsonresponse,true);
print_r($nvarrayval);