【问题标题】:How to create an JSON file in php/javascript? [closed]如何在 php/javascript 中创建 JSON 文件? [关闭]
【发布时间】:2015-06-06 07:00:16
【问题描述】:

我想创建一个以下格式的 JSON 文件。我是 JSON 新手,所以我不知道如何创建以 JSON 格式显示的数据。在此先感谢

{
            "data": [
                [
                    "Tiger Nixon",
                    "System Architect",
                    "Edinburgh",
                    "5421",
                    "2011\/04\/25",
                    "$320,800"
                ],
                [
                    "Garrett Winters",
                    "Accountant",
                    "Tokyo",
                    "8422",
                    "2011\/07\/25",
                    "$170,750"
                ],
                [
                    "Ashton Cox",
                    "Junior Technical Author",
                    "San Francisco",
                    "1562",
                    "2009\/01\/12",
                    "$86,

    000"
            ],
    [
                "Donna Snider",
                "Customer Support",
                "New York",
                "4226",
                "2011\/01\/25",


"$112,000"
        ]
    ]
}

【问题讨论】:

标签: javascript php json


【解决方案1】:

你可以这样开始:

$str = '{
    "data": [
        [ "Tiger Nixon", "System Architect", "Edinburgh", "5421", "2011\/04\/25", "$320,800" ],
        [ "Garrett Winters", "Accountant", "Tokyo", "8422", "2011\/07\/25", "$170,750" ],
        [ "Ashton Cox", "Junior Technical Author", "San Francisco", "1562", "2009\/01\/12", "$86,000" ],
        [ "Donna Snider", "Customer Support", "New York", "4226", "2011\/01\/25", "$112,000" ]
    ]
}';

$json = json_decode($str);
$res = $json->{'data'};

foreach($res as $data) {
    echo "<pre>";
    print_r($data);
}

【讨论】:

  • 我尝试从数据库中获取 JSON 数据..
  • 投反对票的人能解释一下原因吗?
猜你喜欢
  • 2016-07-11
  • 2023-03-15
  • 2021-12-05
  • 1970-01-01
  • 1970-01-01
  • 2019-03-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多