gpt4 book ai didi

php - PHP从JSON获取值(value)

转载 作者:行者123 更新时间:2023-12-02 06:38:36 24 4
gpt4 key购买 nike

假设我有这个JSON:

{
"achievement": [
{
"title": "Ready for Work",
"description": "Sign up and get validated",
"xp": 50,
"difficulty": 1,
"level_req": 1
},
{
"title": "All Around Submitter",
"description": "Get one piece of textual content approved in all five areas.",
"xp": 500,
"difficulty": 2,
"level_req": 1
}
}

而且我正在尝试通过PHP:
$string = file_get_contents("achievements.json");
$json_a=json_decode($string,true);

$getit = $json_a->achievement['title'][1];

我正在尝试获取成就的第一个“id”,即 READY FOR WORK

我该如何解决?

最佳答案

当您将json_decode的第二个参数设置为true时,它将返回一个数组。

$json_a=json_decode($string,true);

返回一个数组。
$getit = $json_a['achievement'][1]['title'];

关于php - PHP从JSON获取值(value),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12598149/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com