开发者

encoding PHP array to Javascript (JSON)

开发者 https://www.devze.com 2023-04-07 17:19 出处:网络
how do I get [{}] in JSON? If I encode arr开发者_JAVA技巧ay() in PHP, the JSON result is []. What is [{}] in JS anyway?

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_encoded, 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 :)

0

精彩评论

暂无评论...
验证码 换一张
取 消