简体   繁体   English

如何通过foreach从JSON读取以插入表

[英]How can read from JSON by foreach to insert to table

I have this json like : 我有这样的json:

{
data: [
{
_id: 6,
Logo: "http://s3-eu-west-1.amazonaws.com/korabia-eg/images/Logos/Leagues/6.png",
matches: [
{
matchId: 1393036,
competitionId: 6,
teamAId: 18299,
teamALogo: "http://www.datasportsgroup.com/images/clubs/50x50/18299.png",
teamBId: 733,
teamBLogo: "http://www.datasportsgroup.com/images/clubs/50x50/733.png",
scoreA: 2,
scoreB: 2,
status: "Played",
timing: "2019-02-15T17:00:00Z",
}
],
}
],
}

and i need way to add this data to table in SQL by using foreach, 我需要通过使用foreach将此数据添加到SQL中的表的方法,

How can do it? 怎么办

    <?php 
    $str=file_get_contents("https://www.so3ody.com/api/get_matches_widget?compId=0&dateFrom=2019/2/15&dateTo=2019/2/16&teamId=0&isWeek=true&roundId=0&week=0&seassonId=0");
$ar=json_decode($str,true);// json to array parsing
$data_ar=$ar['data'];//array
//print_r($data_ar);
foreach($data_ar as $key=>$val)
{
    echo $_id=$val["_id"]; // fetchi _id
    echo "<br>";
    echo $_id=$val["Logo"];// fetching Logo
    echo "<br>";


    $matches_array=$val["matches"];//match array
    foreach($matches_array as $key1=>$value1)
    {
        echo $value1["matchId"];
        echo $value1["competitionId"];

    }

}
    ?>

在此处输入图片说明

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM