json_decode索引为数字时自动排序问题解决方法-创新互联
小编给大家分享一下json_decode索引为数字时自动排序问题解决方法,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
成都创新互联公司专注于企业全网整合营销推广、网站重做改版、孟津网站定制设计、自适应品牌网站建设、H5场景定制、商城网站建设、集团公司官网建设、成都外贸网站制作、高端网站制作、响应式网页设计等建站业务,价格优惠性价比高,为孟津等各大城市提供网站开发制作服务。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”完美解决问题。
解决方法:变成 " " + 数字即可,例如:" 18", " 19"
{ "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" } ] } } }
以上是“json_decode索引为数字时自动排序问题解决方法”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联成都网站设计公司行业资讯频道!
另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。
网站名称:json_decode索引为数字时自动排序问题解决方法-创新互联
网站网址:http://hbruida.cn/article/cccesc.html