2011-10-31 158 views
-2

我正在使用json解碼獲取一些數組。json解碼獲取值特定數據

返回的對象看起來是這樣的

Array 
    (
[0] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103005 
     [ga] => 
     [gsis] => 55267 
     [gt] => REG 
     [h] => BAL 
     [hnn] => ravens 
     [hs] => 30 
     [q] => F 
     [rz] => 0 
     [t] => 1:00 
     [v] => ARI 
     [vnn] => cardinals 
     [vs] => 27 
    ) 

[1] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103003 
     [ga] => 
     [gsis] => 55268 
     [gt] => REG 
     [h] => CAR 
     [hnn] => panthers 
     [hs] => 21 
     [q] => F 
     [rz] => 0 
     [t] => 1:00 
     [v] => MIN 
     [vnn] => vikings 
     [vs] => 24 
    ) 

[2] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103001 
     [ga] => 
     [gsis] => 55269 
     [gt] => REG 
     [h] => HOU 
     [hnn] => texans 
     [hs] => 24 
     [q] => F 
     [rz] => 0 
     [t] => 1:00 
     [v] => JAC 
     [vnn] => jaguars 
     [vs] => 14 
    ) 

[3] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103000 
     [ga] => 
     [gsis] => 55270 
     [gt] => REG 
     [h] => NYG 
     [hnn] => giants 
     [hs] => 20 
     [q] => F 
     [rz] => 0 
     [t] => 1:00 
     [v] => MIA 
     [vnn] => dolphins 
     [vs] => 17 
    ) 

[4] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103004 
     [ga] => 
     [gsis] => 55271 
     [gt] => REG 
     [h] => STL 
     [hnn] => rams 
     [hs] => 31 
     [q] => F 
     [rz] => 0 
     [t] => 1:00 
     [v] => NO 
     [vnn] => saints 
     [vs] => 21 
    ) 

[5] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103002 
     [ga] => 
     [gsis] => 55272 
     [gt] => REG 
     [h] => TEN 
     [hnn] => titans 
     [hs] => 27 
     [q] => F 
     [rz] => 0 
     [t] => 1:00 
     [v] => IND 
     [vnn] => colts 
     [vs] => 10 
    ) 

[6] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103007 
     [ga] => 
     [gsis] => 55273 
     [gt] => REG 
     [h] => BUF 
     [hnn] => bills 
     [hs] => 23 
     [q] => F 
     [rz] => 0 
     [t] => 4:05 
     [v] => WAS 
     [vnn] => redskins 
     [vs] => 0 
    ) 

[7] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103006 
     [ga] => 
     [gsis] => 55274 
     [gt] => REG 
     [h] => DEN 
     [hnn] => broncos 
     [hs] => 10 
     [q] => F 
     [rz] => 0 
     [t] => 4:05 
     [v] => DET 
     [vnn] => lions 
     [vs] => 45 
    ) 

[8] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103008 
     [ga] => 
     [gsis] => 55275 
     [gt] => REG 
     [h] => PIT 
     [hnn] => steelers 
     [hs] => 25 
     [q] => F 
     [rz] => 0 
     [t] => 4:15 
     [v] => NE 
     [vnn] => patriots 
     [vs] => 17 
    ) 

[9] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103010 
     [ga] => 
     [gsis] => 55277 
     [gt] => REG 
     [h] => SEA 
     [hnn] => seahawks 
     [hs] => 12 
     [q] => F 
     [rz] => 0 
     [t] => 4:15 
     [v] => CIN 
     [vnn] => bengals 
     [vs] => 34 
    ) 

[10] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103009 
     [ga] => 
     [gsis] => 55276 
     [gt] => REG 
     [h] => SF 
     [hnn] => 49ers 
     [hs] => 20 
     [q] => F 
     [rz] => 0 
     [t] => 4:15 
     [v] => CLE 
     [vnn] => browns 
     [vs] => 10 
    ) 

[11] => stdClass Object 
    (
     [d] => Sun 
     [eid] => 2011103011 
     [ga] => 
     [gsis] => 55278 
     [gt] => REG 
     [h] => PHI 
     [hnn] => eagles 
     [hs] => 34 
     [q] => F 
     [rz] => 0 
     [t] => 8:20 
     [v] => DAL 
     [vnn] => cowboys 
     [vs] => 7 
    ) 

[12] => stdClass Object 
    (
     [d] => Mon 
     [eid] => 2011103100 
     [ga] => 
     [gsis] => 55279 
     [gt] => REG 
     [h] => KC 
     [hnn] => chiefs 
     [hs] => 0 
     [q] => P 
     [rz] => 0 
     [t] => 8:30 
     [v] => SD 
     [vnn] => chargers 
     [vs] => 0 
    ) 

) 

現在,如果我justed想打印特定陣列信息。我該如何去做這件事。例如。

以上數組中。我只需要[gsis] => 55279的數組中的信息。

+0

不應該我們現在有一些視覺教程等如何使用數組和對象樹和東西? – mario

+0

[在JSON中獲取特定值]的可能重複(http://stackoverflow.com/questions/7737673/get-a-specific-value-in-json) – mario

回答

0

您需要循環它們直到。做一個功能。

function search_object(array $object_array, $desired_number) { 
    foreach($object_array as $one) { 
     if($one->gsis == $desired_number) { 
      return $one; 
     } 
    } 
    //no result found 
    return null; 
}