【发布时间】:2021-10-21 03:11:43
【问题描述】:
我想从这个 Json 中获取用户名(david)的数据,我看到了类似的问题,我尝试了 100 多次但我做不到,如果可能的话,我需要准确的答案。 提前致谢
{
"related_assets": [],
"orders": [],
"auctions": [],
"supports_wyvern": true,
"top_ownerships": [
{
"owner": {
"user": {
"username": "david"
},
"",
"address": "",
"config": ""
},
"quantity": "1"
}
],
"ownership": null,
"highest_buyer_commitment": null
}
我的编码如下:
<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
//the second parameter turns the objects into an array
$decodedData = json_encode($response, true);
$owner = $decodedData['top_ownerships'][0]['owner'];
$username = $owner['user']['username'];
echo $username;
}
输出是“ 请帮忙谢谢
【问题讨论】:
-
这能回答你的问题吗? How do I extract data from JSON with PHP?