简体   繁体   English

如何在PHP上使用json_decode

[英]How to use json_decode on PHP

I have the following JSON string: 我有以下JSON字符串:

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

Need to parse this string with PHP for getting client_id value. 需要使用PHP解析此字符串以获取client_id值。 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? 如何使用响应数组获取client_id值? 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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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