encoding PHP array to Javascript (JSON)
how do I get [{}]
in JSON? If I encode arr开发者_JAVA技巧ay()
in PHP, the JSON result is []
. What is [{}]
in JS anyway?
Thanks
you can use: array(new stdClass)
which when json_encode
d, should end up to be [{}]
To answer your second question of "what is [{}]
anyway?", well it is simple:
it's an array, whose only element is an object with no members in it.
[{}]
is an array containing an object. JSON is an object and you can have a JSONArray within it and more objects within that. Don't overthink the data structure :)
精彩评论