-1

One of URL's return JSON format that start like this

[
{ "name" : "Some Name",
  "price":  "20"

} ]

How can i read this type of Json ?

nskotow
  • 9
  • 4

2 Answers2

0

Use json_decode

$data = '[{"name":"Some Name", "price":"20"}]';
$data = json_decode($data);
foreach($data as $output){
    echo $output->name;
}
No NAME
  • 159
  • 1
  • 10
0
<?php

$json = '[
{ "name" : "Some Name",
  "price":  "20"

} ]';



$json = json_decode($json,true);

echo $json[0]['name'];
echo $json[0]['price'];
Huzoor Bux
  • 1,026
  • 4
  • 20
  • 46