json_decode 索引為數(shù)字時自動排序問題解決方法
json_encode 索引為數(shù)字,自動排序問題
使用son_encode 給前端返回數(shù)據(jù),結果順序不對,經(jīng)debug調(diào)試,發(fā)現(xiàn)是json_encode 函數(shù)的問題;
{
"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"
}
]
}
}
}
解決辦法:在數(shù)字索引前加個空格。如“ 19” “ 18”完美解決問題。
解決方法:變成 " " + 數(shù)字即可,例如:" 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 索引為數(shù)字時自動排序問題解決方法的文章就介紹到這了,更多相關json_decode 數(shù)字索引自動排序內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
優(yōu)雅而高效的JavaScript?try...catch語句詳解(js異常處理)
這篇文章主要給大家介紹了關于JavaScript中try...catch語句的相關資料,也就是js異常處理方法,try...catch是JavaScript中的錯誤處理機制,它的作用是捕獲和處理可能發(fā)生的錯誤,以避免程序崩潰,需要的朋友可以參考下2024-01-01
JavaScript數(shù)組排序小程序?qū)崿F(xiàn)解析
這篇文章主要介紹了JavaScript數(shù)組排序小程序?qū)崿F(xiàn)解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下2020-01-01

