码迷,mamicode.com
首页 > 编程语言 > 详细

javascript相关,格式转化

时间:2017-03-29 10:27:09      阅读:166      评论:0      收藏:0      [点我收藏+]

标签:tmp   orm   []   程序   for   解析   pre   相关   transform   

比如这样的数据:

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相关,格式转化

标签:tmp   orm   []   程序   for   解析   pre   相关   transform   

原文地址:http://www.cnblogs.com/hupengyin/p/6638297.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!