json_decode 索引為數(shù)字時(shí)自動(dòng)排序問題解決方法
json_encode 索引為數(shù)字,自動(dòng)排序問題
使用son_encode 給前端返回?cái)?shù)據(jù),結(jié)果順序不對(duì),經(jīng)debug調(diào)試,發(fā)現(xiàn)是json_encode 函數(shù)的問題;
{
"code": 0,
"msg": "請(qǐng)求成功!",
"data": {
"2018-10": {
"17": [
{
"id": 730,
"uid": "118209",
"is_read": false,
"biggest_high": 0,
"first_read_at": "",
"stock_name": "長春燃?xì)?,
"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ù)字索引前加個(gè)空格。如“ 19” “ 18”完美解決問題。
解決方法:變成 " " + 數(shù)字即可,例如:" 18", " 19"
{
"code": 0,
"msg": "請(qǐng)求成功!",
"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": "長春燃?xì)?,
"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"
}
]
}
}
}
到此這篇關(guān)于json_decode 索引為數(shù)字時(shí)自動(dòng)排序問題解決方法的文章就介紹到這了,更多相關(guān)json_decode 數(shù)字索引自動(dòng)排序內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
BootStrap Table前臺(tái)和后臺(tái)分頁對(duì)JSON格式的要求
Bootstrap是一款前端非常流行的框架,其中的表格更為大家經(jīng)常使用。下面通過本文給大家介紹BootStrap Table前臺(tái)和后臺(tái)分頁對(duì)JSON格式的要求,一起看看吧2017-06-06
javascript實(shí)現(xiàn)瀑布流動(dòng)態(tài)加載圖片原理
這篇文章主要為大家詳細(xì)介紹了javascript實(shí)現(xiàn)瀑布流動(dòng)態(tài)加載圖片原理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-08-08
JavaScript結(jié)合Bootstrap仿微信后臺(tái)多圖文界面管理
這篇文章主要為大家詳細(xì)介紹了js結(jié)合Bootstrap仿微信后臺(tái)多圖文界面管理,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2016-07-07
JavaScript實(shí)現(xiàn)按Ctrl鍵打開新頁面
這篇文章主要介紹了JavaScript實(shí)現(xiàn)按Ctrl鍵打開新頁面的例子,本文方法適用HTML5環(huán)境中,需要的朋友可以參考下2014-09-09
js中回調(diào)函數(shù)的學(xué)習(xí)筆記
這篇文章主要介紹了js中回調(diào)函數(shù)的相關(guān)知識(shí),需要的朋友可以參考下2014-07-07
使用Three.js制作一個(gè)3D獎(jiǎng)牌頁面
本文將使用React+Three.js技術(shù)棧,制作一個(gè)專屬的3D獎(jiǎng)牌頁面,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起動(dòng)手試一試2022-01-01

