84669 person learning
152542 person learning
20005 person learning
5487 person learning
7821 person learning
359900 person learning
3350 person learning
180660 person learning
48569 person learning
18603 person learning
40936 person learning
1549 person learning
1183 person learning
32909 person learning
rt:我现在是比较笨的方法,把单个json循环单个拼接;如果json数据大的话,效率会比较低吧!然后又想着用JSON.stringify变成字符串后,在正则去掉{}什么的;不知道还有其他方法吗?
闭关修行中......
'{"a":"1","b":"2"}'.replace(/"|{|}/g, "").replace(/,/g, ";")
Object.keys({"a":"1","b":"2"}).map(function(key){return key+':'+info[key]}).join(';');
这样行不行:
'use strict'; var info = {a: '1', b: '2'}; var keys = Object.keys(info); var str = keys .reduce((p, key, i) => p + key + ':' + info[key] + (i === keys.length - 1 ? '' : ';'), ''); console.log(str); //a:1;b:2
你是要解析json吗?可以直接用each()或者for也可以
json
each()
for
我觉得效率是一样的吧
可以用jQuery的map工具方法
var obj = {"a":"1","b":"2","c":"3"}; var str = $.map(obj,function(n,index){return ''+index+':'+n;}).join(';');//"a:1;b:2;c:3"
var obj = {"a":"1","b":"2","c":"3"}; var str = JSON.stringify(obj).replace(/"|{|}/g, "").replace(/,/g, ";")
'{"a":"1","b":"2"}'.replace(/"|{|}/g, "").replace(/,/g, ";")
这样行不行:
你是要解析
json
吗?可以直接用each()
或者for
也可以我觉得效率是一样的吧
可以用jQuery的map工具方法