简体   繁体   English

获取特定的JSON响应值

[英]get Specific JSON Response Value

json response as below: json回复如下:

{"Success":true,"ErrorCode":0,"UserInformation":{"UserID":"19"}......

how do I get the UserID value by using json_decode ? 如何使用json_decode获取UserID值?

I tried the below code with no luck. 我尝试了下面的代码没有运气。

$Response = json_decode($Response[2]);
echo $Response[0][0][0];

This should work: 这应该工作:

<?php

$json = '{"Success":true, "ErrorCode":"0","UserInformation":{"UserID":"19"}}';
$response = json_decode($json, true);

echo $userId = $response["UserInformation"]["UserID"];

?>

Please check the PHP documentation of json_decode at http://php.net/json_decode You can use object as well if you skip the second parameter of the json_decode function. 请在http://php.net/json_decode上查看json_decode的PHP文档。如果跳过json_decode函数的第二个参数,也可以使用对象。

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

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