如何将此响应xml转换为json

时间:2019-10-15 03:45:00

标签: php json xml laravel

我有这样的xml响应 enter image description here 我想像这样更改为响应json

{
    "data": {
        "tanggal": "20191015",
        "jam": "103346",
        "BeneficiaryAccount": "12340097034787"
    }
}

1 个答案:

答案 0 :(得分:0)

要将XML数据转换为JSON:

<table class="table table-responsive table-striped table-bordered table-hover table-condensed" 
   id="edp">
    <thead>
      <tr>
        <th>EDP</th>
        <th>Name</th>
        <th>Course</th>
        <th>Year</th>
        <th>Dept.</th>
        <th>Clearance</th>
        <th>View</th>
      </tr>
    </thead>
    <tbody>
      <?php foreach($data as $display)
            {   
            echo "<tr>";
            echo "  
                <td>".$display->EDP."</td>
                <td>".$display->Lname.', '.$display->Fname.', '.$display->Mname."</td>
                <td>".$display->Course."</td>
                <td>".$display->Cyear."</td>
                <td>".$display->Dept."</td>
                <td>".$display->Status."</td>
                <td><a href='".base_url().'office/viewClearance/'.$display->EDP."'><img 
                class='viewicon' src='".base_url().'assets/icons/view.png'."'></td>
                </tr>";
            }
            ?>
    </tbody>

这可以。