Enjin API(JSON)到PHP第2部分

时间:2014-03-24 16:10:36

标签: php json

我试图弄清楚如何从http://www.natomilcorp.com/api/get-tags

获取数据

但我的工作方式与http://www.natomilcorp.com/api/get-users

的工作方式相同
<?php

$content = file_get_contents('http://natomilcorp.com/api/get-tags');
$array = json_decode($content, TRUE);


foreach ($array as $key => $value) {

}

?>

应该返回类似:Major

具有该等级的每个用户的等级+ id的id。我怎么能这样做?

  • 数据我试图获得。

Array([tags] =&gt; Array([766910] =&gt; Array([name] =&gt; Major [visible] =&gt; 2 [users] =&gt; Array([0] =&gt; 200159 ))[766912] =&gt;数组([名称] =&gt;队长[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 2261591))[766913] =&gt;数组([ name] =&gt; 1st Lieutenant [visible] =&gt; 2 [users] =&gt; Array([0] =&gt; 9054053))[766914] =&gt;数组([name] =&gt; 2nd Lieutenant [visible] =&gt; 2 [用户] =&gt;数组([0] =&gt; 8987889))[773490] =&gt;数组([名称] =&gt;警长头等[可见] =&gt; 2 [用户] =&gt ;数组([0] =&gt; 7725577))[773492] =&gt;数组([名称] =&gt;警长[可见] =&gt; 1 [用户] =&gt;数组([0] =&gt; 1060956 [ 1] =&gt; 7302252 [2] =&gt; 8757300 [3] =&gt; 8863799 [4] =&gt; 8965561 [5] =&gt; 9261041))[773493] =&gt;数组([名称] =&gt;下士[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 3021405 [1] =&gt; 7007387 [2] =&gt; 9139763 [3] =&gt; 9213371))[773494] = &gt;数组([name] =&gt;私有头等舱[可见] =&gt; 2 [用户] =&gt;阵列([0] =&gt; 2200849 [1] =&gt; 3641961 [2] =&gt; 9178511 [3] =&gt; 9261322 [4] =&gt; 9323849 [5] =&gt; 9389371 [6] =&gt; 9430088))[773495] =&gt;数组([名称] =&gt;私人[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 114357 [1] =&gt; 261041 [2] =&gt; 304466 [3] =&gt ; 549312 [4] =&gt; 1118346 [5] =&gt; 1710685 [6] =&gt; 2141867 [7] =&gt; 3211667 [8] =&gt; 3310027 [9] =&gt; 35538​​05 [10] =&gt; 4528862 [11] =&gt; 7379434 [12] =&gt; 8403949 [13] =&gt; 8428123 [14] =&gt; 8650774 [15] =&gt; 8910960 [16] =&gt; 9010718 [17] =&gt; 9141940 [18] =&gt; 9223268 [19] =&gt; 9276028 [20] =&gt; 9308336 [21] =&gt; 9324049 [22] =&gt; 9343007 [23] =&gt; 9379991 [24] =&gt; 9388650 [ 25] =&gt; 9388744 [26] =&gt; 9501913))[773499] =&gt;数组([名称] =&gt;招募[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 89975 [1] =&gt; 205838 [2] =&gt; 384035 [3] =&gt ; 1607344 [4] =&gt; 3131066 [5] =&gt; 6461552 [6] =&gt; 7126984 [7] =&gt; 7233456 [8] =&gt; 8594187 [9] =&gt; 9210020 [10] =&gt; 9319294 [11] =&gt; 9324467 [12] =&gt; 9368201 [13] =&gt; 9401020 [14] =&gt; 9401208 [15] =&gt; 9411271 [16] =&gt; 9412511 [17] =&gt; 9442152 [18] =&gt; 9472151 [19] =&gt; 9481048 [20] =&gt; 9507716 [21] =&gt; 9519155 [22] =&gt; 9519665 [23] =&gt; 9524202 [24] =&gt; 9524528 [ 25] =&gt; 9527256 [26] =&gt; 9528148 [27] =&gt; 9528464 [28] =&gt; 9532974 [29] =&gt; 9532993))[794713] =&gt;数组([名称] =&gt; NMC成员[可见] =&gt; 0 [用户] =&gt;数组([0] =&gt; 89975 [1] =&gt; 114357 [2] =&gt; 200159 [3] = &gt; 205838 [4] =&gt; 304466 [5] =&gt; 384035 [6] =&gt; 549312 [7] =&gt; 857679 [8] =&gt; 870831 [9] =&gt; 1060956 [10] =&gt; ; 1118346 [11] =&gt; 1607344 [12] =&gt; 1710685 [13] =&gt; 2141867 [14] =&gt; 2200849 [15] =&gt; 2261591 [16] =&gt; 3021405 [17] =&gt; 3131066 [18] =&gt; 3211667 [19] =&gt; 3310027 [20] =&gt; 35538​​05 [21] =&gt; 3641961 [22] =&gt; 4528862 [23] =&gt; 5888412 [24] =&gt; 6461552 [25] =&gt; 7007387 [26] =&gt; 7126984 [27] =&gt; 7233456 [28] =&gt; 7302252 [29] =&gt; 7379434 [30] =&gt; 7725577 [31] =&gt; 8403949 [ 32] =&gt; 8428123 [33] =&gt; 8594187 [34] =&gt; 8650774 [35] =&gt; 8757300 [36] =&gt; 8863799 [37] =&gt; 8910960 [38] =&gt; 8965561 [39 ] =&gt; 8987889 [40] =&gt; 9010718 [41] =&gt; 9017629 [42] =&gt; 9054053 [43] =&gt; 9139763 [44] =&gt; 9141940 [45] =&gt; 9178511 [46] =&gt; 9210020 [47] =&gt; 9213371 [48] =&gt; 9223268 [49] =&gt; 926104 1 [50] =&gt; 9261322 [51] =&gt; 9276028 [52] =&gt; 9289688 [53] =&gt; 9308336 [54] =&gt; 9319294 [55] =&gt; 9323849 [56] =&gt; 9324049 [57] =&gt; 9324467 [58] =&gt; 9343007 [59] =&gt; 9361657 [60] =&gt; 9368201 [61] =&gt; 9379991 [62] =&gt; 9388650 [63] =&gt; 9388744 [64] =&gt; 9389371 [65] =&gt; 9401020 [66] =&gt; 9401208 [67] =&gt; 9411271 [68] =&gt; 9412511 [69] =&gt; 9430088 [70] =&gt; 9442152 [71] =&gt; 9472151 [72] =&gt; 9481048 [73] =&gt; 9501913 [74] =&gt; 9507716 [75] =&gt; 9519155 [76] =&gt; 9519665 [77] =&gt; 9524202 [78] =&gt; 9524528 [79] =&gt; 9527256 [80] =&gt; 9528148 [81] =&gt; 9528464 [82] =&gt; 9532974 [83] =&gt; 9532993))[905780] =&gt;数组([名称] =&gt;保留/非活动[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 1116431 [1] =&gt; 1146450 [2] =&gt; 1327008 [3] =&gt; 3488556 [4] =&gt; 4057254 [5] =&gt; 4109011 [6] =&gt; 4442271 [7] =&gt; 5075797 [8] =&gt; 6348486 [9] =&gt; 6727549 [10] = &gt; 7482138 [11] =&gt; 7669434 [12] =&gt; 7810956 [13] =&gt; 7813040 [14] =&gt; 7845349 [15] =&gt; 7873320 [16] =&gt; 8163829 [17] =&gt; ; 8610931 [18] =&gt; 8720229 [19] =&gt; 8758932 [20] =&gt; 8944586 [21] =&gt; 8988410 [22] =&gt; 9009221 [23] =&gt; 9016644 [24] =&gt; 9143121))[916781] =&gt; Array([name] =&gt; High Command [visible] =&gt; 2 [users] =&gt; Array([0] =&gt; 192868))[950454] =&gt;数组([名称] =&gt;(AF)第二中尉[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 870831 [1] =&gt; 5888412 [2] =&gt; 9017629 [ 3] =&gt; 9289688 [4] =&gt; 9361657))[950472] =&gt;数组([名称] =&gt;(AF)第一中尉[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 857679))[964515] =&gt;数组([名称] =&gt; 8周服务功能区1A [可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 857679 [1] =&gt; 3021405 [2] =&gt; 8428123) )[964541] =&gt;数组([名称] =&gt; 8周服务功能区2A [可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 7725577))[964552] =&gt;数组([名称] =&gt; 8周服务功能区4A [可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 200159))[964580] =&gt;数组([名称] =&gt;阿尔特斯战争服务功能区[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 200159 [1] =&gt; 857679 [2] =&gt; 870831 [3 ] =&gt; 1060956 [4] =&gt; 2261591 [5] =&gt; 5888412 [6] =&gt; 7302252 [7] =&gt; 7725577 [8] =&gt; 8757300 [9] =&gt; 8863799 [10] =&gt; 8965561 [11] =&gt; 9054053))[964632] =&gt;数组([名称] =&gt;指挥官表彰[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 2261591 [1] =&gt; 9054053 [2] =&gt; 9139763 [3] =&gt; 9261322))[964807] =&gt;数组([名称] =&gt;执行官表彰[可见] =&gt; 2 [用户] =&gt;数组([0] =&gt; 5888412 [1] =&gt; 8863799 [2] =&gt; 9017629))< / p>

1 个答案:

答案 0 :(得分:1)

应该是

echo $array['tags'][$key]['name'];

您可以看到有一个tags键,因此您在访问时也需要添加它。

工作代码..

<?php
$content = file_get_contents('http://natomilcorp.com/api/get-tags');
$array = json_decode($content, TRUE);
$key = "766910";
echo $array['tags'][$key]['name'];