php解json字符串,如何解码PHP中的JSON字符串?

本文介绍了如何使用PHP的json_decode函数处理JSON结构,展示了如何提取并存储地址信息到会话变量中,包括address1、address2、address3、city和postalCode。
摘要由CSDN通过智能技术生成

print_r是你搞定JSON结构的朋友.

$addresses = json_decode('{"addresses":{"address":[{"@array":"true","@id":"888888","@uri":"xyz","household":{"@id":"44444","@uri":"xyz"},"person":{"@id":"","@uri":""},"addressType":{"@id":"1","@uri":"xyz","name":"Primary"},"address1":"xyz","address2":null,"address3":null,"city":"xyz","postalCode":"111111"}]}}');

$_SESSION['address1'] = $addresses->addresses->address[0]->address1;

$_SESSION['address2'] = $addresses->addresses->address[0]->address2;

$_SESSION['address3'] = $addresses->addresses->address[0]->address3;

$_SESSION['city'] = $addresses->addresses->address[0]->city;

$_SESSION['postalCode'] = $addresses->addresses->address[0]->postalCode;

print_r($_SESSION);

结果是:

Array

(

[address1] => xyz

[address2] =>

[address3] =>

[city] => xyz

[postalCode] => 111111

)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值