json中出现意外的“ s”

时间:2019-03-16 16:57:30

标签: php json postman

我尝试构建restAPI 当我在postMan上检查代码时,出现错误,提示数据不完整

这是我用于创建文件的代码

<?php
header("Access-Control-Allow-Origin: *");
header("Content-Type: application/json; charset=UTF-8");
header("Access-Control-Allow-Methods: POST");
header("Access-Control-Max-Age: 3600");
header("Access-Control-Allow-Headers: Content-Type, Access-Control-Allow-Headers, Authorization, X-Requested-With");

include_once 'database.php';
include_once 'inquery.php';
$database = new Database();
$db = $database->getConnection();
$product = new Inquery($db);
$jsn = file_get_contents("php://input");
$data = json_decode($jsn);
if(
    !empty($data->enqType) &&
    !empty($data->title) &&
    !empty($data->deptid) &&
    !empty($data->enq_body)&&
    !empty($data->taskPriority)
){
    $t = time();
    $product->enqType = $data->enqType;
    $product->title = $data->title;
    $product->deptid = $data->deptid;
    $product->enq_body = $data->enq_body;
    $product->taskPriority = $data->taskPriority;
    $product->addedDate = $t;
    $product->addedBy = 0;
    if($product->create()){
        http_response_code(201);
        echo json_encode(array("message" => "Product was created."));
    } else{
        http_response_code(503);
        echo json_encode(array("message" => "Unable to create product."));
    }
}
else{
    http_response_code(400);
    echo json_encode(array("message" => "Unable to create product. Data is incomplete."));
}?>

这是我的json文件,其中包含我需要的内容

{
"title" : "title1",
"enqType" : 1,
"deptid" : 3,
"enq_body" : "some text",
"taskPriority" : 1}

我尝试了所有事情,发现该代码不接受字符串 在我的检查中,我发现了以下错误:

  • 下面共享的图片中出现意外的“ s”:

enter image description here

0 个答案:

没有答案