[Solved] How to Parse JSON with PHP?


You need do it in following manner:-

<?php

 $data="{
  "metrics": {
    "timers": [
      {
        "name": "com.android.timer.launchtime",
        "startTime": 1232138988989,
        "duration_ms": 1900
      },
      {
        "name": "com.android.timer.preroll-load-time",
        "startTime": 1232138988989,
        "duration_ms": 1000
      }
    ]
  }
}";
$new_array = json_decode($data); //convert json data into array
echo "<pre/>";print_r($new_array); //print array
foreach ($new_array->metrics->timers as $new_arr){ // iterate through array
    echo $new_arr->name.'<br/>'; // rest you can do also same   
}
?>

Output:- https://eval.in/407418

4

solved How to Parse JSON with PHP?