我想用PHP解析这个JSON

时间:2016-04-16 10:22:15

标签: php json

我想在PHP中解析这个JSON。我不知道如何解析数据:

  stdClass Object ( 
    [coord] => stdClass Object ( 
      [lon] => 138.93 
      [lat] => 34.97 
    ) 
    [weather] => Array (
      [0] => stdClass Object ( 
        [id] => 803 
        [main] => Clouds 
        [description] => broken clouds 
        [icon] => 04n 
      )
    ) 
    [base] => stations 
    [main] => stdClass Object ( 
      [temp] => 290.738 
      [pressure] => 1026.59 
      [humidity] => 94 
      [temp_min] => 290.738 
      [temp_max] => 290.738 
      [sea_level] => 1035.92 
      [grnd_level] => 1026.59 ) 
      [wind] => 
        stdClass Object ( 
          [speed] => 6.81 
          [deg] => 225.502 ) 
          [clouds] => stdClass Object ( 
            [all] => 56 ) 
          [dt] => 1460799951 
          [sys] => stdClass Object ( 
            [message] => 0.0131 
            [country] => JP 
            [sunrise] => 1460751040 
            [sunset] => 1460798268 
          ) 
          [id] => 1851632 
          [name] => Shuzenji 
          [cod] => 200 
    ) 

1 个答案:

答案 0 :(得分:1)

这不是jSON,它是一个PHP对象。

要获取它,您可以像这样使用->。假设它在$data var中,你想获得天气数组:

$weather = $data -> weather; // retrieve weather array

要获取main对象部分,您可以执行以下操作:

$mainObject = $data -> main; // retrieve main Object
$temp = $data -> main -> temp; // retrieve temp from main Object