dongqichang7988 2014-05-23 03:05
浏览 480
已采纳

PHP json_decode()是否总是保留JSON数组的数组顺序?

Does the string

 ["first","second","third"]

always preserve array order and result in the PHP array

array('first','second','third');

when using json_decode()? I realize the answer is NO for objects, but I am asking about a string representing an array as input.

  • 写回答

2条回答 默认 最新

  • dongyunqin7307 2014-05-23 03:10
    关注

    Yes. Arrays are ordered by definition, and JSON preserves this.

    The JSON specification says:

    An array structure is a pair of square bracket tokens surrounding zero or more values. The values are separated by commas. The order of the values is significant.

    The last sentence implies that a JSON encoder or decoder that changes the order is not in conformance with the specification. I can't find anything in the PHP documentation that explicitly says that it observes this requirement, but I think it can be assumed since it claims to be implementing JSON.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 创建一个数据库(要创建的表和记事本的代码截图))
  • ¥15 有没有整苹果智能分拣线上图像数据
  • ¥20 有没有人会这个东西的
  • ¥15 cfx考虑调整“enforce system memory limit”参数的设置
  • ¥30 航迹分离,航迹增强,误差分析
  • ¥15 Chrome Manifest扩展引用Ajax-hook库拦截请求失败
  • ¥15 用Ros中的Topic通讯方式控制小乌龟的速度,走矩形;编写订阅器代码
  • ¥15 LLM accuracy检测
  • ¥15 pycharm添加远程解释器报错
  • ¥15 如何让子窗口鼠标滚动独立,不要传递消息给主窗口