嗨,我需要为Parse错误找到解决方案:语法错误,意外的T_OBJECT_OPERATOR这里是我的代码和我的json字符串。
<?
include"db.inc.php";//database connection
$order = "SELECT * FROM wp_postmeta";
$result = mysql_query($order);
$array = array();
while ($row=mysql_fetch_array($result)){
if($row[meta_id]>=557 && $row[meta_key]=='gdlr-soccer-player-settings'){
$temp_ar = json_decode($row[meta_value],true);
array_push($array,$temp_ar);
}
}
/*$count = count($array);
for($i = 0;$i<$count;$i++){
echo $array[$i];
echo "<div></div>";
}*/
print_r($array->player-info->first-name);
?>
和json
{"player-info":{"first-name":"Antonio","last-name":"Russo","squad":"","position":"Portiere","position-ab":"","nationality":"","date-of-birth":"","height":"","weight":"","games-played":"","minutes-played":"","starts":"","substitution-on":"","substitution-off":"","facebook":"","twitter":"","youtube":"","instagram":""},"player-stats":{"passes":"","passing-accuracy":"","passing-accuracy-opp":"","duels-won":"","duels-lost":"","duels-won-percent":"","aerial-duels-won":"","aerial-duels-lost":"","aerial-duels-won-percent":"","recoveries":"","tackles-won":"","tackles-lost":"","tackles-won-percent":"","clearances":"","blocks":"","interceptions":"","penalties-conceded":"","fouls-won":"","fouls-conceded":"","yellow-cards":"","red-cards":"","goals":"","penalty-goals":"","minutes-per-goal":"","total-shots-on-target":"","total-shots-off-target":"","shooting-accuracy":"","successful-crosses":"","unsuccessful-crosses":"","successful-crosses-percent":"","assists":"","chances-created":"","penalties-won":"","offsides":""},"biography":{"biography":""},"gallery":{"player-gallery":""}}
在此更新结构
Array ( [0] => Array ( [player-info] => Array ( [first-name] => Antonio [last-name] => Russo [squad] => [position] => Portiere [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [1] => [2] => Array ( [player-info] => Array ( [first-name] => Domenico [last-name] => Galluccio [squad] => [position] => Portiere [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [3] => Array ( [player-info] => Array ( [first-name] => Carmelo [last-name] => Contro [squad] => [position] => Difensore [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [4] => [5] => Array ( [player-info] => Array ( [first-name] => Michelangelo [last-name] => Ierace [squad] => [position] => Difensore [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [6] => Array ( [player-info] => Array ( [first-name] => Raffaele [last-name] => Maurici [squad] => [position] => Difensore [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [7] => Array ( [player-info] => Array ( [first-name] => Serafino [last-name] => Mamone [squad] => [position] => Difensore [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [8] => Array ( [player-info] => Array ( [first-name] => Vincenzo [last-name] => Startari [squad] => [position] => Difensore [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [9] => Array ( [player-info] => Array ( [first-name] => Gabriele [last-name] => Guerrisi [squad] => [position] => Laterale [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [10] => Array ( [player-info] => Array ( [first-name] => Giovanni [last-name] => Nava [squad] => [position] => Laterale [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [11] => Array ( [player-info] => Array ( [first-name] => Mario [last-name] => Foti [squad] => [position] => Laterale [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [12] => Array ( [player-info] => Array ( [first-name] => Michele [last-name] => Abramo [squad] => [position] => Laterale [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [13] => Array ( [player-info] => Array ( [first-name] => Pasquale [last-name] => Zappia [squad] => [position] => Laterale [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [14] => Array ( [player-info] => Array ( [first-name] => Valentino [last-name] => Tassone [squad] => [position] => Laterale [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [15] => Array ( [player-info] => Array ( [first-name] => Antonio [last-name] => Sorrenti [squad] => [position] => Attaccante [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [16] => Array ( [player-info] => Array ( [first-name] => Claudio [last-name] => Monterosso [squad] => [position] => Attaccante [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [17] => Array ( [player-info] => Array ( [first-name] => Domenico [last-name] => Cosoleto [squad] => [position] => Attaccante [position-ab] => [nationality] => [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [goals] => 50 [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) [18] => Array ( [player-info] => Array ( [first-name] => Peppe [last-name] => ZAPPIA [squad] => [position] => COGLIONE [position-ab] => [goals] => [penalty-goals] => [minutes-per-goal] => [total-shots-on-target] => [nationality] => AFRICANO [date-of-birth] => [height] => [weight] => [games-played] => [minutes-played] => [starts] => [substitution-on] => [substitution-off] => [facebook] => [twitter] => [youtube] => [instagram] => ) [player-stats] => Array ( [passes] => [passing-accuracy] => [passing-accuracy-opp] => [duels-won] => [duels-lost] => [duels-won-percent] => [aerial-duels-won] => [aerial-duels-lost] => [aerial-duels-won-percent] => [recoveries] => [tackles-won] => [tackles-lost] => [tackles-won-percent] => [clearances] => [blocks] => [interceptions] => [penalties-conceded] => [fouls-won] => [fouls-conceded] => [yellow-cards] => [red-cards] => [total-shots-off-target] => [shooting-accuracy] => [successful-crosses] => [unsuccessful-crosses] => [successful-crosses-percent] => [assists] => [chances-created] => [penalties-won] => [offsides] => ) [biography] => Array ( [biography] => ) [gallery] => Array ( [player-gallery] => ) ) )
任何想法都要感谢!
这是解决方案!
$array[0]['player-info']['first-name']
答案 0 :(得分:1)
在while
循环中为数组标识符添加适当的引号。改变这个:
if($row[meta_id]>=557 && $row[meta_key]=='gdlr-soccer-player-settings'){
$temp_ar = json_decode($row[meta_value],true);
array_push($array,$temp_ar);
}
到此:
if($row['meta_id'] >=557 && $row['meta_key']=='gdlr-soccer-player-settings'){
$temp_ar = json_decode($row['meta_value'],true);
array_push($array,$temp_ar);
}
同时更改以下声明:
print_r($array->player-info->first-name);
为:
print_r($array['player-info']['first-name']); // since you're working with an array, not an object