0
解析JSON文件到MySQL數據庫時遇到了一些麻煩。這是一些Facebookstats的出口。在MySQL數據庫中解析具有多個級別的JSON文件
因爲我已經多次導出多個頁面,所以重要的是我在數據庫中有相應的ID。
的JSONfile(或捲曲來自Facebook)看起來是這樣的:
{
"data": [
{
"name": "impressions",
"period": "week",
"values": [
{
"value": 123456789,
"end_time": "2016-01-01T08:00:00+0000"
},
{
"value": 12345678,
"end_time": "2016-01-02T08:00:00+0000"
},
{
"value": 1234567,
"end_time": "2016-01-03T08:00:00+0000"
},
{
"value": 123456,
"end_time": "2016-01-04T08:00:00+0000"
},
{
"value": 12345,
"end_time": "2016-01-05T08:00:00+0000"
}
],
"title": "Weekly Impressions",
"description": "The number of impressions seen of any content associated with your Page. (Total Count)",
"id": "101010101010\/insights\/page_impressions\/week"
}
],
"paging": {
"previous": "1",
"next": "2"
}
}
我想,理想情況下,分析這些數據到MySQL數據庫中,看起來像這樣:
id value end_time
101010101010 123456789 2016-01-01T08:00:00+0000
101010101010 12345678 2016-01-02T08:00:00+0000
101010101010 1234567 2016-01-03T08:00:00+0000
101010101010 123456 2016-01-04T08:00:00+0000
101010101010 12345 2016-01-05T08:00:00+0000
我希望有人有一些想法:-)
你嘗試過什麼? PHP可以輕鬆將JSON解碼爲一個數組。一些嵌套的foreach很容易獲得數據,所以你可以將插入到表中。 –