
获取 get 返回的 json 字符串中的值
使用 php 的 json_encode 函数将 json 字符串编码为 php 字符串时,若要访问字符串中的值,可使用 json_decode 函数。
问题中给出的 json 字符串示例为:
{
"headers": {
"content-type": ["application/json;charset=utf-8"],
"content-length": ["110"]
},
"statuscode": 200
}使用 json_decode 函数,我们可以将其解码为 php 对象或数组,具体取决于 json_object_as_array 参数的设置:
Easily find JSON paths within JSON objects using our intuitive Json Path Finder
30
立即学习“PHP免费学习笔记(深入)”;
$json = json_decode($jsonAsString, true); // true 表示解码为数组 $statusCode = $json['statusCode']; // 获取 statusCode 值
这样,便可成功访问 json 字符串中的 statuscode 值。
以上就是如何用PHP获取JSON字符串中的值?的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号