我使用flightstates API来创建实时航班状态。 他们在api中提供警报消息。他们说“To use the Alerts API, the developer must implement a web service that accepts an HTTP POST and parses an Alerts Message, then set up a rule specifying that service as the destination.”。 我创建了这样的Web服务:
$data = json_decode(file_get_contents('php://input'), true);
$que = mysqli_query($con,"insert into firetable (datas) values ('$data')");
但它存储值“Array”。 如何将数据存储在数据库中?
"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'等存储到数据库中?
答案 0 :(得分:0)
// remove json_decode
$data = json_decode(file_get_contents('php://input'), true);
到
$data = file_get_contents('php://input');
$que = mysqli_query($con,"insert into firetable (datas) values ('$data')");
数据将以JSON格式存储在DB中。
答案 1 :(得分:0)
只需使用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
有关该功能的更多信息: enter link description here