URL 处的 Null 上的 JsonDecode
JsonDecode on Null at an URL
我正在制作一个插件,通过编码 URL 从外部服务器获取数据。为了解码插件的输出,我使用的是 JsonDecode,但它每次都返回“NULL”。
代码:
$json = file_get_contents($goodurl);
$data = json_decode($json);
var_dump($data);
这是请求 URL 时的响应:
{
"schemaVersion": "1.0",
"catalogueVersion": "4.0.5651.20898",
"encoding": "UTF-8",
"action": "info",
"query": "catalogue",
"success": "true",
"response": {
"title": "Presentations 2Go",
"description": "Presentations2Go videoserver is an innovative solution to simply capture presentations and\/or lectures on video. The video image of the presenter is linked with the presentation and stored for later (re)use.",
"logoUrl": "https:\/\/DEMO-FORMS.presentations2go.eu\/P2G\/images\/logo\/logo.png",
"languages": [
{"lang": "en"},
{"lang": "nl"},
{"lang": "de"},
{"lang": "fr"},
{"lang": "kr"},
{"lang": "no"},
{"lang": "pt"},
{"lang": "dk"},
{"lang": "cn"},
{"lang": "ar"},
{"lang": "se"},
{"lang": "it"},
{"lang": "es"},
{"lang": "ru"},
{"lang": "cy"},
{"lang": "tw"}
],
"videoCount": "380",
"webmaster": "support@presentations2go.eu"
}
}
这是 JSON 中的输出:
object(stdClass)#83 (7) {
["schemaVersion"]=> string(3) "1.0"
["catalogueVersion"]=> string(14) "4.0.5651.20898"
["encoding"]=> string(5) "UTF-8"
["action"]=> string(4) "info"
["query"]=> string(9) "catalogue"
["success"]=> string(4) "true"
["response"]=> object(stdClass)#84 (6) {
["title"]=> string(17) "Presentations 2Go"
["description"]=> string(207) "Presentations2Go videoserver is an innovative solution to simply capture presentations and/or lectures on video. The video image of the presenter is linked with the presentation and stored for later (re)use."
["logoUrl"]=> string(63) "https://DEMO-FORMS.presentations2go.eu/P2G/images/logo/logo.png"
["languages"]=> array(16) {
[0]=> object(stdClass)#85 (1) {
["lang"]=> string(2) "en"
}
[1]=> object(stdClass)#86 (1) {
["lang"]=> string(2) "nl"
}
[2]=> object(stdClass)#87 (1) {
["lang"]=> string(2) "de"
}
[3]=> object(stdClass)#88 (1) {
["lang"]=> string(2) "fr"
}
[4]=> object(stdClass)#89 (1) {
["lang"]=> string(2) "kr"
}
[5]=> object(stdClass)#90 (1) {
["lang"]=> string(2) "no"
}
[6]=> object(stdClass)#91 (1) {
["lang"]=> string(2) "pt"
}
[7]=> object(stdClass)#92 (1) {
["lang"]=> string(2) "dk"
}
[8]=> object(stdClass)#93 (1) {
["lang"]=> string(2) "cn"
}
[9]=> object(stdClass)#94 (1) {
["lang"]=> string(2) "ar"
}
[10]=> object(stdClass)#95 (1) {
["lang"]=> string(2) "se"
}
[11]=> object(stdClass)#96 (1) {
["lang"]=> string(2) "it"
}
[12]=> object(stdClass)#97 (1) {
["lang"]=> string(2) "es"
}
[13]=> object(stdClass)#98 (1) {
["lang"]=> string(2) "ru"
}
[14]=> object(stdClass)#99 (1) {
["lang"]=> string(2) "cy"
}
[15]=> object(stdClass)#100 (1) {
["lang"]=> string(2) "tw"
}
}
["videoCount"]=> string(3) "378"
["webmaster"]=> string(27) "support@presentations2go.eu"
}
}
我经验不足 JSON 所以我怀疑其中可能存在语法错误。但我不确定如何解决它。
您得到的是对象而不是数组。
简单地写:
$data = json_decode($json, true);
接收关联数组。
使用此代码
$data = json_decode($json,true);
您得到的是对象而不是数组。
接收关联数组。
$data = json_decode($json, true);
或者您可以像
一样访问或获取对象的值
echo $data->catalogueVersion;
大家都已经告诉你把json_decode
设置为true,当true返回的对象会被转换成关联数组,link
$data = json_decode($json, true);
我建议使用下面的代码来查看您的数组。这样更容易阅读。
echo "<pre>";
print_r($array);
echo "</pre>";
我正在制作一个插件,通过编码 URL 从外部服务器获取数据。为了解码插件的输出,我使用的是 JsonDecode,但它每次都返回“NULL”。
代码:
$json = file_get_contents($goodurl);
$data = json_decode($json);
var_dump($data);
这是请求 URL 时的响应:
{
"schemaVersion": "1.0",
"catalogueVersion": "4.0.5651.20898",
"encoding": "UTF-8",
"action": "info",
"query": "catalogue",
"success": "true",
"response": {
"title": "Presentations 2Go",
"description": "Presentations2Go videoserver is an innovative solution to simply capture presentations and\/or lectures on video. The video image of the presenter is linked with the presentation and stored for later (re)use.",
"logoUrl": "https:\/\/DEMO-FORMS.presentations2go.eu\/P2G\/images\/logo\/logo.png",
"languages": [
{"lang": "en"},
{"lang": "nl"},
{"lang": "de"},
{"lang": "fr"},
{"lang": "kr"},
{"lang": "no"},
{"lang": "pt"},
{"lang": "dk"},
{"lang": "cn"},
{"lang": "ar"},
{"lang": "se"},
{"lang": "it"},
{"lang": "es"},
{"lang": "ru"},
{"lang": "cy"},
{"lang": "tw"}
],
"videoCount": "380",
"webmaster": "support@presentations2go.eu"
}
}
这是 JSON 中的输出:
object(stdClass)#83 (7) {
["schemaVersion"]=> string(3) "1.0"
["catalogueVersion"]=> string(14) "4.0.5651.20898"
["encoding"]=> string(5) "UTF-8"
["action"]=> string(4) "info"
["query"]=> string(9) "catalogue"
["success"]=> string(4) "true"
["response"]=> object(stdClass)#84 (6) {
["title"]=> string(17) "Presentations 2Go"
["description"]=> string(207) "Presentations2Go videoserver is an innovative solution to simply capture presentations and/or lectures on video. The video image of the presenter is linked with the presentation and stored for later (re)use."
["logoUrl"]=> string(63) "https://DEMO-FORMS.presentations2go.eu/P2G/images/logo/logo.png"
["languages"]=> array(16) {
[0]=> object(stdClass)#85 (1) {
["lang"]=> string(2) "en"
}
[1]=> object(stdClass)#86 (1) {
["lang"]=> string(2) "nl"
}
[2]=> object(stdClass)#87 (1) {
["lang"]=> string(2) "de"
}
[3]=> object(stdClass)#88 (1) {
["lang"]=> string(2) "fr"
}
[4]=> object(stdClass)#89 (1) {
["lang"]=> string(2) "kr"
}
[5]=> object(stdClass)#90 (1) {
["lang"]=> string(2) "no"
}
[6]=> object(stdClass)#91 (1) {
["lang"]=> string(2) "pt"
}
[7]=> object(stdClass)#92 (1) {
["lang"]=> string(2) "dk"
}
[8]=> object(stdClass)#93 (1) {
["lang"]=> string(2) "cn"
}
[9]=> object(stdClass)#94 (1) {
["lang"]=> string(2) "ar"
}
[10]=> object(stdClass)#95 (1) {
["lang"]=> string(2) "se"
}
[11]=> object(stdClass)#96 (1) {
["lang"]=> string(2) "it"
}
[12]=> object(stdClass)#97 (1) {
["lang"]=> string(2) "es"
}
[13]=> object(stdClass)#98 (1) {
["lang"]=> string(2) "ru"
}
[14]=> object(stdClass)#99 (1) {
["lang"]=> string(2) "cy"
}
[15]=> object(stdClass)#100 (1) {
["lang"]=> string(2) "tw"
}
}
["videoCount"]=> string(3) "378"
["webmaster"]=> string(27) "support@presentations2go.eu"
}
}
我经验不足 JSON 所以我怀疑其中可能存在语法错误。但我不确定如何解决它。
您得到的是对象而不是数组。 简单地写:
$data = json_decode($json, true);
接收关联数组。
使用此代码
$data = json_decode($json,true);
您得到的是对象而不是数组。
接收关联数组。
$data = json_decode($json, true);
或者您可以像
一样访问或获取对象的值echo $data->catalogueVersion;
大家都已经告诉你把json_decode
设置为true,当true返回的对象会被转换成关联数组,link
$data = json_decode($json, true);
我建议使用下面的代码来查看您的数组。这样更容易阅读。
echo "<pre>";
print_r($array);
echo "</pre>";