我有一个传递参数的url使用json_encode每个值,如下所示:$json = array( 'countryId' => $_GET['CountryId'], 'productId' => $_GET['ProductId'], 'status' => $_GET['ProductId'], 'opId' => $_GET['OpId']);echo json_encode($json);返回的结果为:{ "countryId":"84", "productId":"1", "status":"0", "opId":"134"}我可以json_decode用来解析每个值以进行进一步的数据处理吗?
3 回答
largeQ
TA贡献2039条经验 获得超7个赞
json_decode() 如果第二个值为true,将返回一个对象或数组:
$json = '{"countryId":"84","productId":"1","status":"0","opId":"134"}';
$json = json_decode($json, true);
echo $json['countryId'];
echo $json['productId'];
echo $json['status'];
echo $json['opId'];
Cats萌萌
TA贡献1805条经验 获得超9个赞
json_decode将返回与原始编码相同的数组。为了即时,如果您
$array = json_decode($json, true);
echo $array['countryId'];
要么
$obj= json_decode($json);
echo $obj->countryId;
这些都将回显84。我认为json_encode和json_decode函数名称是不言自明的...
- 3 回答
- 0 关注
- 874 浏览
添加回答
举报
0/150
提交
取消