dro62273 2019-03-16 16:57
浏览 57

在json中出乎意料的's'

i try to build restAPI when i check my code on postMan i got error that data incomplete

this is my code for create file

<?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."));
}?>

this is my json file that contains what i need

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

i try all things, i see that this code dosen't accept string in my checks i recived this errors :

  • unexpected 's' in the image shared below:

enter image description here

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
    • ¥15 python的qt5界面
    • ¥15 无线电能传输系统MATLAB仿真问题
    • ¥50 如何用脚本实现输入法的热键设置
    • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
    • ¥30 深度学习,前后端连接
    • ¥15 孟德尔随机化结果不一致
    • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
    • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
    • ¥15 谁有desed数据集呀