我想解析json并将所有数据保存到数据库中。这是我的儿子:
[{
"date": "2016/04/01",
"mac": "C9:3F:C1:B1:6F:1F",
"id": 16,
"dest": 0,
"melvalue": 22
}, {
"date": "2016/03/31",
"mac": "C9:3F:C1:B1:6F:1F",
"id": 1,
"dest": 0,
"melvalue": 0
}, {
"date": "2016/03/30",
"mac": "C9:3F:C1:B1:6F:1F",
"id": 2,
"dest": 0,
"melvalue": 0
}]我该怎么做?请帮帮忙。
{
"date": "2016/03/17",
"mac": "C9:3F:C1:B1:6F:1F",
"id": 15,
"dest": 12,
"melvalue": 0
}将是我的一排桌子。
发布于 2016-04-01 17:26:16
-Steps将类似于在控制器函数中从源读取所有数据。
$arraytoIterate = json_decode('Yor json string here to go');
-- Create a model for that table
-- create dataArray and save the data in your controllers function as below $arraytoIterate = json_decode('Yor json string here to go');
foreach($arraytoIterate as $newArr){
// hope table columns name will be same as of json object column name
ModelName::create($newArr) // for adding records
}https://stackoverflow.com/questions/36352360
复制相似问题