duanpasi6287 2015-03-30 21:08 采纳率: 100%
浏览 51

错误解析错误:语法错误,意外T_OBJECT_OPERATOR

Hi at all i need to find a solution for Parse error: syntax error, unexpected T_OBJECT_OPERATOR here is my code and my json string.

<?
      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);
        ?>

and 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":""}}

Update here the structure

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] => ) ) )

any idea thanks at all!

Here the solution!

$array[0]['player-info']['first-name']
  • 写回答

1条回答 默认 最新

  • douwei8295 2015-03-30 21:13
    关注

    Add proper quotes to your array identifiers in the while loop. Change this:

    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);
    }
    

    to this:

    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);
    }
    

    Also change the following statement:

    print_r($array->player-info->first-name);
    

    to:

    print_r($array['player-info']['first-name']); // since you're working with an array, not an object
    
    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图