【发布时间】:2015-03-27 04:24:57
【问题描述】:
我有这个代码
$status = array(
"message"=>"error",
"club_id"=>$_club_id,
"status"=>"1",
"membership_info"=>array(),
);
echo json_encode($status);
这个函数返回json:{"message":"error","club_id":275,"status":"1","membership_info":[]}
但我需要这样的 json:
{"message":"error","club_id":275,"status":"1","membership_info":{}}
【问题讨论】:
-
这就是json如何表示一个数组。 [] 代表 Json 中的数组
-
当前格式有什么问题?
-
这是正确的 json 格式。数组用大括号括起来 - "[ ]"。
-
@jogesh_pi 问题是它生成不一致的 json(空时为数组,非空时为对象)。其他解析器对此有疑问:stackoverflow.com/questions/26725138/…
-
这里的前三个cmets不正确。