【发布时间】:2021-12-09 03:44:49
【问题描述】:
我有 PHP 代码从我订阅的网站返回以下值,我的问题是如何循环遍历这个数组并回显每一行?除此之外,如果可能的话,我想将每条记录插入到 MS-SQL 数据库中,最好是通过批量插入。
{
"count": 8,
"messages": [
{
"t": 1638413506,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.026467, 121.721675\nTime: 2021-12-02 10:51:46\nhttp://maps.google.com/?q=17.026467,121.721675",
"x": 121.721674983,
"y": 17.0264666677,
"rt": 0,
"p": {}
},
{
"t": 1638415192,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.023507, 121.721527\nTime: 2021-12-02 11:19:52\nhttp://maps.google.com/?q=17.023507,121.721527",
"x": 121.721526655,
"y": 17.0235066672,
"rt": 0,
"p": {}
},
{
"t": 1638416233,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.023335, 121.721730\nTime: 2021-12-02 11:37:13\nhttp://maps.google.com/?q=17.023335,121.721730",
"x": 121.721729978,
"y": 17.0233349999,
"rt": 0,
"p": {}
},
{
"t": 1638426180,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.023990, 121.721965\nTime: 2021-12-02 14:23:00\nhttp://maps.google.com/?q=17.023990,121.721965",
"x": 121.721965027,
"y": 17.0239899993,
"rt": 0,
"p": {}
},
{
"t": 1638430480,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.014735, 121.721372\nTime: 2021-12-02 15:34:40\nhttp://maps.google.com/?q=17.014735,121.721372",
"x": 121.721371651,
"y": 17.0147350003,
"rt": 0,
"p": {}
},
{
"t": 1638439534,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.014727, 121.721405\nTime: 2021-12-02 18:05:34\nhttp://maps.google.com/?q=17.014727,121.721405",
"x": 121.721405029,
"y": 17.0147266666,
"rt": 0,
"p": {}
},
{
"t": 1638450807,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Dalig, Burgos, Isabela, Philippines\nCoordinates: 17.014760, 121.722102\nTime: 2021-12-02 21:13:27\nhttp://maps.google.com/?q=17.014760,121.722102",
"x": 121.722101657,
"y": 17.0147599995,
"rt": 0,
"p": {}
},
{
"t": 1638467462,
"f": 1073743361,
"tp": "evt",
"et": "(NotificationNo: GPS0006)\nAlert!\n\nMOTION DETECTION: Tractor #16\n\nSuspicious movement of vehicle is detected while engine is off! \n\nCurrent Location: Bacnor East, Burgos, Isabela, Philippines\nCoordinates: 17.015082, 121.721735\nTime: 2021-12-03 01:51:02\nhttp://maps.google.com/?q=17.015082,121.721735",
"x": 121.721735001,
"y": 17.0150816669,
"rt": 0,
"p": {}
}
]
}
【问题讨论】:
-
您的 SQL Server 版本是多少?如果是 SQL Server 2016 或更高版本,您可以将整个 JSON 传递给存储过程,以便一次性加载所有内容,即批量插入。
标签: php sql-server