How to output this json {},{} with php?
I was unable to output this:
[{"title":"London","foo":"bar"},{"title":"Istanbul"开发者_如何转开发,"foo":"bar"}]
I cannot make comma here: },{
I can output this [{"title":"London","foo":"bar"}]
but not the first example.
This will produce the desired output:
$data = array(
array("title" => "London",
"foo" => "bar"
),
array("title" => "Istanbul",
"foo" => "bar"
)
);
echo json_encode($data);
Make sure you create your arrays correctly. For more information have a look at the documentation for json_decode
.
精彩评论