首页 >> js开发 >> JavaScriptjson_decode 索引为数字时自动排序问题解决方法
JavaScriptjson_decode 索引为数字时自动排序问题解决方法
发布时间: 2021年1月13日 | 浏览:
| 分类:js开发
json_encode 索引为数字,自动排序问题使用son_encode 给前端返回数据,结果顺序不对,经debug调试,发现是json_encode 函数的问题;
{
"code": 0,
"msg": "请求成功!",
"data": {
"2021-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"
}
]
},
"2021-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"
}
]
}
}
}
{
"code": 0,
"msg": "请求成功!",
"data": {
"2021-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"
}
]
},
"2021-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": {
"2021-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"
}
]
},
"2021-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"
}
]
}
}
}
{
"code": 0,
"msg": "请求成功!",
"data": {
"2021-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"
}
]
},
"2021-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"
}
]
}
}
}
{
"code": 0,
"msg": "请求成功!",
"data": {
"2021-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"
}
]
},
"2021-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"
}
]
}
}
}
{
"code": 0,
"msg": "请求成功!",
"data": {
"2021-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"
}
]
},
"2021-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": {
"2021-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"
}
]
},
"2021-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"
}
]
}
}
}
{
"code": 0,
"msg": "请求成功!",
"data": {
"2021-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"
}
]
},
"2021-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"
}
]
}
}
}
相关文章:
- jsVue切换组件实现返回后不重置数据,保留历史设置操作js大全
- js代码JavaScript中reduce()的5个基本用法示例
- jsJS中的变量作用域(console版)js大全
- js完美解决通过IP地址访问VUE项目的问题js大全
- js在Echarts图中给坐标轴加一个标识线markLinejs大全
- js使用 Github Actions 自动部署 Angular 应用到 Github Pages的方法js大全
- jsmpvue 项目初始化及实现授权登录的实现方法js大全
- js一文读懂vue动态属性数据绑定(v-bind指令)js大全
- jsVue清除定时器setInterval优化方案分享js大全
- js解决elementUI 切换tab后 el_table 固定列下方多了一条线问题js大全