解析错误:语法错误,意外' $ author' (T_VARIABLE)

时间:2017-04-08 01:16:20

标签: php json

我的php文件:

    if($operation=='upload'){
    if(isset($data -> paper) && !empty($data -> paper) && isset($data -> paper -> author) && isset($data -> paper -> description) && isset($data -> paper -> title)){

      $author = $data -> paper -> author;
      $description= $data -> paper -> description;
      $title = $data -> paper -> title;

      echo $fun -> uploadPaper($author,$description,$title);
    }

JSON

  {
   "operation": "upload",
   "paper": {
    "author": "Mark Watson",
    "description": "The book writing about AI by Mark Waton",
    "title": "Practical Artificial Intelligence Programming With Java"
}
}

当我通过post方法将json发送到服务器时,出现错误:

解析错误:语法错误,意外' $ author'第78行的D:\ xampp \ htdocs \ server \ index.php中的(T_VARIABLE)

我真的不知道发生了什么!请告诉我

1 个答案:

答案 0 :(得分:0)

在你的第二个if语句中,你的左括号有些错误/奇怪。 这是固定版本:

if ($operation == 'upload') {

    if(isset($data -> paper) && !empty($data -> paper) && isset($data -> paper -> author) && isset($data -> paper -> description) && isset($data -> paper -> title)) {

        $author = $data->paper->author;
        $description = $data->paper->description;
        $title = $data->paper->title;

        echo $fun->uploadPaper($author, $description, $title);

    }

}