简体   繁体   中英

How to use json_decode on PHP

I have the following JSON string:

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

Need to parse this string with PHP for getting client_id value. using the following command:

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

how do I use the response array for getting client_id value? The following command does not work and return empty string:

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

use this code

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM