如何在php / javascript中创建JSON文件? [关闭]

问题描述:

I Want to create an JSON file in the following format. I'm new to the JSON so i can't get how to create this data displayed in the JSON format. Thanks in advance

{
            "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的新手,所以我无法知道如何创建以JSON格式显示的数据。 提前致谢 p>

  {
“data”:[
 [
“Tiger Nixon”,
“System Architect”,
“Edinburgh”,
  “5421”,
“2011 \ / 04 \ / 25”,
“$ 320,800”
],
 [
“Garrett Winters”,
“会计师”,
“东京”,
“  8422“,
”2011 \ / 07 \ / 25“,
”$ 170,750“
],
 [
”Ashton Cox“,
”初级技术作者“,
”旧金山“,\  n“1562”,
“2009 \ / 01 \ / 12”,
“$ 86,
 
 000”
],
 [
“Donna Snider”,
“客户支持”,
  n“纽约”,
“4226”,
“2011 \ / 01 \ / 25”,
 
 
“$ 112,000”
  ] 
] 
} 
  code>  pre> 
  div>

You can start like this :

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