json_decode 索引为数字,自动排序问题

json_encode 索引为数字,自动排序问题


使用son_encode 给前端返回数据,结果顺序不对,经debug调试,发现是json_encode 函数的问题;

{
  "code": 0,
  "msg": "请求成功!",
  "data": {
    "2018-10": {
      "17": [
        {
          "id": 730,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "长春燃气",
          "stock_code": "600333",
          "in_timed_at": 1539756681,
          "price": "6.4"
        }
      ],
      "18": [
        {
          "id": 735,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "天孚通信",
          "stock_code": "300394",
          "in_timed_at": 1539828137,
          "price": "17.7"
        }
      ],
      "19": [
        {
          "id": 748,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "科大讯飞",
          "stock_code": "002230",
          "in_timed_at": 1539941525,
          "price": "31.87"
        }
      ],
      "09": [
        {
          "id": 706,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "温州宏丰",
          "stock_code": "300283",
          "in_timed_at": 1539048922,
          "price": "4.83"
        }
      ]
    },
    "2018-09": {
      "29": [
        {
          "id": 702,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "新美星",
          "stock_code": "300509",
          "in_timed_at": 1538212392,
          "price": "13.36"
        }
      ]
    }
  }
}

解决办法:在数字索引前加个空格。如“ 19” “ 18”完美解决问题。

{
  "code": 0,
  "msg": "请求成功!",
  "data": {
    "2018-10": {
      " 19": [
        {
          "id": 748,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "科大讯飞",
          "stock_code": "002230",
          "in_timed_at": 1539941525,
          "price": "31.87"
        }
      ],
      " 18": [
        {
          "id": 735,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "天孚通信",
          "stock_code": "300394",
          "in_timed_at": 1539828137,
          "price": "17.7"
        }
      ],
      " 17": [
        {
          "id": 730,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "长春燃气",
          "stock_code": "600333",
          "in_timed_at": 1539756681,
          "price": "6.4"
        }
      ],
      " 09": [
        {
          "id": 706,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "温州宏丰",
          "stock_code": "300283",
          "in_timed_at": 1539048922,
          "price": "4.83"
        }
      ]
    },
    "2018-09": {
      " 29": [
        {
          "id": 702,
          "uid": "118209",
          "is_read": false,
          "biggest_high": 0,
          "first_read_at": "",
          "stock_name": "新美星",
          "stock_code": "300509",
          "in_timed_at": 1538212392,
          "price": "13.36"
        }
      ]
    }
  }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值