json在php中创建带有类别和子类别的

时间:2018-06-27 12:41:04

标签: php arrays json nested

我的json的PHP代码

<?php
include ('db.php');

$ID = $_GET['id'];

function get_data()
{
    $ID = $_GET['id'];
    $query = mysql_query("select * from json_table where chall_no='$ID' ");
    $temp = array();

    while ($row=mysql_fetch_array($query)) {
        $temp[] = array(
            'docDate' => $row["date"],
            'totInvValue' => $row["total_amount"],
            'transMode' => 1,
            'transDistance' => $row["transdistance"],
            'transporterName' => $row["transport"],
            'transporterId' => $row["tgstin_no"],
            'transDocNo' => "",
            'transDocDate' => "",
            'vehicleNo' => "",
            'vehicleType' => "R",
            'mainHsnCode' => 5407,
            'itemNo' => 1,
            'quantity' => $row["total_meter"],
            'qtyUnit' => "MTR",
            'taxableAmount' => $row["amount_after_less"],
            'sgstRate' => $row["sgstrate"],
            'cgstRate' => $row["cgstrate"],
            'igstRate' => $row["igstrate"],
            'cessRate' => 0
        );
    }
    return json_encode($temp, JSON_NUMERIC_CHECK);
}

$file_name = $ID.'.json';

if (file_put_contents('json/' . $file_name, get_data())) {
    echo " Json File created";
} else {
    echo 'There is some error';
}

?>

希望将此作为输出。 如何分为类别和子类别。 还有如何在json文件中获取它。 使用php创建json文件.gettting json文件但如何进行分类。 如何在我的json文件中获取以下内容 1)版本:“ 1.0.0501”, 2)billLists:[{ 3)itemList:[{ 4)从日期中删除\。

{
    "version":"1.0.0501",
    "billLists":[{
        "docDate":"27\/06\/2018",
        "totInvValue":5500,
        "transMode":1,
        "transDistance":50,
        "transporterName":"",
        "transporterId":"",
        "transDocNo":"",
        "transDocDate":"",
        "vehicleNo":"",
        "vehicleType":"R",
        "mainHsnCode":5407,
        "itemList":[{
            "itemNo":1,
            "quantity":220,
            "qtyUnit":"MTR",
            "taxableAmount":5000,
            "sgstRate":2.5,
            "cgstRate":2.5,
            "igstRate":0,
            "cessRate":0
        }]
    }]
}

0 个答案:

没有答案