在php中读取json输出

时间:2013-11-11 08:24:02

标签: php json

如何在php下面阅读json数据? 我有“ $ json = json_decode($ data,true); 和 我试过“ $ json-> {'screenShareCode'}; ”但是给我一个错误? :(


    array(5) {
      ["screenShareCode"]=>
      string(9) "887874819"
      ["appletHtml"]=>
      string(668) ""
      ["presenterParams"]=>
      string(396) "aUsEdyygd6Yi5SqaJss0="
      ["viewerUrl"]=>
      string(65) "http://api.screenleap.com/v2/viewer/814222219?accountid=myid"
      ["origin"]=>
      string(3) "API"
    }

4 个答案:

答案 0 :(得分:1)

您显示的输出不是json。它似乎是一个print_r'ed数组。

请参阅http://json.org/example

答案 1 :(得分:0)

您正在寻找json_encode(http://de2.php.net/json_encode

答案 2 :(得分:0)

您的输出是常规数组而不是JSON,因此您可以将其作为常规PHP数组访问:

$x = $array['screenShareCode']

答案 3 :(得分:0)

您发布的是数组,而不是对象。因为您传递了json_decode true的第二个参数,所以它使用关联数组而不是对象进行响应。

要访问关联数组的属性,您可以执行$json['screenShareCode']

之类的操作