donglang1976 2015-06-26 07:13
浏览 26
已采纳

Json在URL上的Null上编码

I'm making a plugin that gets data from an external server through an encoded URL. To decode the output of the plugin I am using a JsonDecode, but it comes back 'NULL'everytime.

The code:

    $json = file_get_contents($goodurl);
    $data = json_decode($json);
    var_dump($data);

This is the response when requesting the 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"
  }
}

And this is the output in 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" 
    } 

}

I'm not that experienced JSON so I suspect there might be a syntax error in there. But I'm not sure what and how to solve it.

  • 写回答

4条回答 默认 最新

  • douye6812 2015-06-26 07:17
    关注

    You're getting an object instead of an array. Simply write:

    $data = json_decode($json, true);
    

    To receive an associative array.

    From the docs: http://php.net/manual/en/function.json-decode.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址