【发布时间】:2015-02-26 18:23:08
【问题描述】:
我有 JSON,需要从中获取一些信息。
<?
$json = {"ship":{"shipname":"Harbinger Navy Issue","shipid":"33155","dna":"33155:3520;6:11561;1:19280;1:19278;1:4349;1:19191;1:2364;2:1248;3:2048;1:31372;3:2488;10:12814;6::"},"high":[{"Heavy Pulse Laser II:3520":6}],"medium":[{"Shield Boost Amplifier I:11561":1},{"Pith A-Type EM Ward Field:19280":1},{"Pith A-Type Thermic Dissipation Field:19278":1},{"Pithum C-Type Adaptive Invulnerability Field:4349":1},{"Pithum A-Type Medium Shield Booster:19191":1}],"low":[{"Heat Sink II:2364":2},{"Capacitor Flux Coil II:1248":3},{"Damage Control II:2048":1}],"rig":[{"Medium Capacitor Control Circuit I:31372":3}],"subsystem":[],"drones":[{"Warrior II:2488":10}],"charge":[{"Conflagration M:12814":6}]};
$obj_o = json_decode($json);
$test = $obj_o->ship->shipname;
$test2 = $obj_o->high->{0};
$test3 = $obj_o->ship->high->{0}->{0};
$test4 = $obj_O->ship->dna;
$test5 = $obj_a[high][1];
//$test6 = $obj_a[medium][1]{1};
$test6 = $result->ship->shipname;
echo 'test6:';
echo $test6;
echo '</br>';
echo 'test5:';
echo $test5;
echo '</br>';
echo $test;
echo '</br>';
echo 'test2:';
echo $test2;
echo '</br>';
echo 'test3:';
echo $test3;
echo '</br>';
?>
我想从 JSON 中选择“高”并将其分成 3 部分:
- 重脉冲激光 II
- 3520
- 6
我该怎么做?
【问题讨论】:
-
$json = {"ship":"foo"};既不是有效的 PHP 也不是有效的 JSON。请在此处发布之前提取一个最小示例。
标签: php arrays json object decode