/** * 将json数据进行排序 * @param {*jason} data */ export function JsonSort(jsonData) { try { let tempJsonObj = {}; let sdic = Object.keys(jsonData).sort(); sdic.map((item, index)=>{ tempJsonObj[item] = jsonData[sdic[index]] }) console.log('将返回的数据进行输出',tempJsonObj); return tempJsonObj; } catch(e) { return jsonData; } }
示例代码 function JsonSort(jsonData) { try { let tempJsonObj = {}; let sdic = Object.keys(jsonData).sort(); sdic.map((item, index)=>{ tempJsonObj[item] = jsonData[sdic[index]] }) return tempJsonObj; } catch(e) { return jsonData; } } let tempJson = {"BopicId": "142","Appid": "100002","Ein": "system","Din": "dsadasd"} JsonSort(tempJson);
效果图