Javascript 如何将动态Json数据添加到Mysql数据库中。

Javascript 如何将动态Json数据添加到Mysql数据库中。,javascript,php,mysql,json,database,Javascript,Php,Mysql,Json,Database,如何将JSON数据添加到数据库中?我有一个脚本正在生成自动更新的JSON数据。我在一本书中读到我应该使用一种叫做 JSON_decode 我想我应该做一些事情,比如,把每个值的值放到表中。然后尝试使用methode JSON_解码,然后对每个进行循环。但我对此不确定。最好的方法是什么?你能告诉我在我的情况下该怎么做,或者举个例子吗 以下是数据: 当前脚本: <?php require_once ('simple_html_dom.php'); $html = @file_get_h

如何将JSON数据添加到数据库中?我有一个脚本正在生成自动更新的JSON数据。我在一本书中读到我应该使用一种叫做

JSON_decode 
我想我应该做一些事情,比如,把每个值的值放到表中。然后尝试使用methode JSON_解码,然后对每个进行循环。但我对此不确定。最好的方法是什么?你能告诉我在我的情况下该怎么做,或者举个例子吗

以下是数据:

当前脚本:

<?php
require_once ('simple_html_dom.php');

$html = @file_get_html('http://csgolounge.com/');
$output = array();

if(!$html) exit(json_encode(array("error" => "Unable to connect to CSGOLounge")));

// Source: http://php.net/manual/en/function.strip-tags.php#86964
function strip_tags_content($text, $tags = '', $invert = FALSE) {
preg_match_all('/<(.+?)[\s]*\/?[\s]*>/si', trim($tags), $tags);
$tags = array_unique($tags[1]);

if(is_array($tags) AND count($tags) > 0) {
    if($invert == FALSE)
        return preg_replace('@<(?!(?:'. implode('|', $tags) .')\b)(\w+)\b.*?>.*?</\1>@si', '', $text);
    else
        return preg_replace('@<('. implode('|', $tags) .')\b.*?>.*?</\1>@si', '', $text);
} elseif($invert == FALSE) {
    return preg_replace('@<(\w+)\b.*?>.*?</\1>@si', '', $text);
}

return $text;
}

foreach($html->find('.matchmain') as $match) {
$when = $match->find('.whenm')[0];
$status = trim($when->find('span')[0]->plaintext) == "LIVE" ? true : false;
$event = $match->find('.eventm')[0]->plaintext;
$time = trim(strip_tags_content($when->innertext));
$id = substr($match->find('a')[0]->href, 8);
    $additional = substr(trim($when->find('span')[$status ? 1 : 0]->plaintext), 4);
$result;

$output[$id]["live"] = $status;
$output[$id]["time"] = $time;
$output[$id]["event"] = $event;

foreach($match->find('.teamtext') as $key => $team) {
    $output[$id]["teams"][$key] = array(
        "name" => $team->find('b')[0]->plaintext,
        "percent" => $team->find('i')[0]->plaintext
    );

    if(@$team->parent()->find('img')[0])
        $result = array("status" => "won", "team" => $key);
    }

if($additional)
    $result = $additional;

if(isset($result))
    $output[$id]["result"] = $result;
}

echo json_encode($output);

您需要按原样将此json数据保存到表中(列的数据类型必须是长文本)。当你为了显示的目的获取数据时,你需要对其进行json_解码,以便它在数组中转换,然后根据需要使用它?是的,我只是想将数据保存到数据库中,但你能举个simpel示例,因为我不是100%确定你的意思吗?你可以这样做,因为你正在使用php将正常值存储到表中。Sry我想我没有理解你的评论,我不想将Json保存到一个表中,该表包含Match id、Team_1、Team_2等子表