【发布时间】:2018-09-21 14:08:25
【问题描述】:
我在项目上工作,那里有服务器发送到我的 php 应用程序 json 数据,然后我将其放入数据库中。 我收到来自服务器的 POST 请求,我可以通过以下方式获取 json: 接收json.php:
$payload = file_get_contents('php://input');
还有JSON的形式:
{
"applicationID": "123",
"applicationName": "temperature-sensor",
"deviceName": "garden-sensor",
"devEUI": "0202020202020202",
"rxInfo": [
{
"gatewayID": "0303030303030303", // ID of the receiving gateway
"name": "rooftop-gateway", // name of the receiving gateway
"time": "2016-11-25T16:24:37.295915988Z", // time when the package was received (GPS time of gateway, only set when available)
"rssi": -57, // signal strength (dBm)
"loRaSNR": 10, // signal to noise ratio
"location": {
"latitude": 52.3740364, // latitude of the receiving gateway
"longitude": 4.9144401, // longitude of the receiving gateway
"altitude": 10.5, // altitude of the receiving gateway
}
}
],
"txInfo": {
"frequency": 868100000, // frequency used for transmission
"dr": 5 // data-rate used for transmission
},
"adr": false, // device ADR status
"fCnt": 10, // frame-counter
"fPort": 5, // FPort
"data": "...", // base64 encoded payload (decrypted)
"object": { // decoded object (when application coded has been configured)
"temperatureSensor": {"1": 25},
"humiditySensor": {"1": 32}
}
}
我是 JSON 的新用户,所以我直接将文本 JSON 放入我的数据库,如下所示:
$payload = file_get_contents('php://input');
$req = $bdd->prepare( '
INSERT INTO nods(payload)
VALUES (:payload);
' );
$req->execute(array('payload' => $payload));
结果: 我想浏览“$payload”并将信息放入 php 变量中,例如:
$applicationID = .... ; $rxInfo[] = .... ;
我已经尝试过类似“foreach”的方法,但我无法成功,请你帮帮我,谢谢:)。
最好的尊重,
迪杜·贾瓦德
【问题讨论】: