【发布时间】:2014-07-16 05:28:51
【问题描述】:
我想使用 PHP 按字母顺序对单行 JSON 数据进行排序。所以最后:
{"one":"morning","two":"afternoon","three":"evening","four":"night"}
变成:
{"four":"night","one":"morning","three":"evening","two":"afternoon"}
我尝试使用ksort 无济于事:
$icons = json_decode(file_get_contents("icons.json"));
ksort($icons);
foreach($icons as $icon => $code){...}
【问题讨论】:
-
能贴出你使用的PHP代码吗?
-
你先打电话给
json_decode()了吗? -
$arr = json_decode($yourJSONString); ksort($arr); -
您是否对数组进行了 var_dump 以查看它是否已正确读取?