我使用FlightStates API创建实时飞行状态。他们在其API中提供了警报消息。他们说:"要使用警报API,开发人员必须实现接受HTTP帖子并解析警报消息的Web服务,然后设置规则,将该服务指定为目的地。"。我创建了这样的网络服务:
$data = json_decode(file_get_contents('php://input'), true);
$que = mysqli_query($con,"insert into firetable (datas) values ('$data')");
但它存储了"数组"值。如何将数据存储在数据库中?
"alert":{
"event":{ },
"dataSource":"Airline",
"dateTimeRecorded":"2017-12-05T08:36:24.957Z",
"rule":{ },
"flightStatus":{
"flightId":"942163187",
"carrierFsCode":"9W",
"flightNumber":"527",
"departureAirportFsCode":"DXB",
"arrivalAirportFsCode":"COK",
"departureDate":{
"dateLocal":"2017-12-05T12:25:00.000",
"dateUtc":"2017-12-05T08:25:00.000Z"
},
"arrivalDate":{
"dateLocal":"2017-12-05T17:50:00.000",
"dateUtc":"2017-12-05T12:20:00.000Z"
},...............
............................
API响应(如这样)(当我将邮寄电子邮件ID作为服务时,我会在电子邮件中收到此响应)。如何将" FlightID"," Flightnumber"等存储到数据库中?
// remove json_decode
$data = json_decode(file_get_contents('php://input'), true);
to
$data = file_get_contents('php://input');
$que = mysqli_query($con,"insert into firetable (datas) values ('$data')");
数据将以JSON格式存储在DB中。
简单地您可以使用json_decode函数:
$obj = json_decode($json,true); // this is the string you are storing in the database
echo $obj['alert'][0]['flightStatus'][0]['flightId']; // here is 942163187
有关该功能的更多信息:在此处输入链接描述