如何在PHP上使用json_decode

时间:2016-12-01 12:25:13

标签: php json

我有以下JSON字符串:

{"createLead":{"client_id":42891}}

需要使用PHP解析此字符串以获取client_id值。 使用以下命令:

$json_result= json_decode('{"createLead":{"client_id":42891}}', true);

如何使用响应数组获取client_id值? 以下命令不起作用并返回空字符串:

$client_id = $json_result['createLead']['client_id'];

1 个答案:

答案 0 :(得分:-2)

使用此代码

<?php
$json = '{"createLead":{"client_id":42891}}';
$json_result= json_decode($json, true);
echo $json_result['createLead']['client_id'];
?>
Output: 42891