javascript相关,格式转化
Posted 阳雪凌空
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript相关,格式转化相关的知识,希望对你有一定的参考价值。
比如这样的数据:
Object {1018: "3", 40101: "727", 40102: "11032", 40201: "130", 40301: "311", 40401: "798", 40501: "978", 40901: "198", 41003: "82", 41101: "1860", 41102: "1968", 41401: "33", 41404: "86", 41501: "467", 41502: "114", 41505: "158", 41601: "22", 41706: "927", 41801: "9153", 41802: "472", 41805: "1779", 42101: "88", 42103: "6", 42201: "420", 42401: "159", 42603: "28", 42801: "7", 42901: "28731", 42905: "24"}
转化成:
[["1018","3"],["40101","727"],["40102","11032"],["40201","130"],["40301","311"],["40401","798"],["40501","978"],["40901","198"],["41003","82"],["41101","1860"],["41102","1968"],["41401","33"],["41404","86"],["41501","467"],["41502","114"],["41505","158"],["41601","22"],["41706","927"],["41801","9153"],["41802","472"],["41805","1779"],["42101","88"],["42103","6"],["42201","420"],["42401","159"],["42603","28"],["42801","7"],["42901","28731"],["42905","24"]]
程序:
function transform(obj){
var arr = [];
for(var item in obj){
var tmp = [];
tmp.push(item);
tmp.push(obj[item]);
arr.push(tmp);
}
return JSON.stringify(arr);
}
JSON.parse()------>用于从一个字符串中解析出json对象
JSON.stringify()------->用于从对象中解析出json字符串
以上是关于javascript相关,格式转化的主要内容,如果未能解决你的问题,请参考以下文章