【问题标题】:JSONArray parsing laravel 4JSONArray解析laravel 4
【发布时间】:2016-07-21 00:37:24
【问题描述】:

我想解析 json 并将所有数据保存到数据库。 这是我的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
}

将是我的一排桌子。

【问题讨论】:

    标签: json laravel-4


    【解决方案1】:

    -步骤将类似于 -- 在控制器函数中从源读取所有数据

    $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
         }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-06-04
      • 1970-01-01
      • 2016-08-12
      • 1970-01-01
      • 2017-08-13
      • 2016-08-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多