如何在PHP中创建与此类似的json对象?
{
"employees": [
{ "firstName":"John" , "lastName":"Doe" },
{ "firstName":"Anna" , "lastName":"Smith" },
{ "firstName":"Peter" , "lastName":"Jones" }
]
}
答案 0 :(得分:21)
您创建一个数组,并将其传递给json_encode
$stuff = array(
'employees' => array(
array('firstName' => 'John', 'lastName' => 'Doe'),
....
)
);
echo json_encode($stuff);