Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 转换地图<;字符串,字符串>;在jquery中插入数组_Javascript_Jquery_Json_Dictionary - Fatal编程技术网

Javascript 转换地图<;字符串,字符串>;在jquery中插入数组

Javascript 转换地图<;字符串,字符串>;在jquery中插入数组,javascript,jquery,json,dictionary,Javascript,Jquery,Json,Dictionary,我在java中有如下映射: "{one=Print, two=Email, three=Download, four=Send to Cloud}"; 我需要在jquery中将上面的字符串转换为数组,循环数组并获取相应的键和值,使用、和方法 var str=“{one=Print,two=Email,three=Download,three=Send to Cloud}”; str //删除起始和结束处的空间 .trim() //获取不带“{”和“}”的字符串` .切片(1,-1) //除以

我在java中有如下映射:

"{one=Print, two=Email, three=Download, four=Send to Cloud}";
我需要在jquery中将上面的字符串转换为数组,循环数组并获取相应的键和值,使用、和方法

var str=“{one=Print,two=Email,three=Download,three=Send to Cloud}”;
str
//删除起始和结束处的空间
.trim()
//获取不带“{”和“}”的字符串`
.切片(1,-1)
//除以``
.split(“,”)
//迭代数组
.forEach(功能(v){
//分开`=`
var val=v.trim().split('=');
log('键:'+val[0]+”,值:“+val[1]”)
})
下面是一个简单的破解:

let arr = jsons.replace('{','').replace('}','').split(',')
arr.map((each)=>{let newVal = each.split('='); return {key: newVal[0], value: newVal[1]}})
试试这个:

function convertString(string) {
  return string.split(', ').map(function(a) {
    var kvArr = a.split('=');
    return {key: kvArr[0], value: kvArr[1]};
  };
}
函数转换字符串(字符串){
string=string.slice(1,string.length-1);
返回string.split(',').map(函数(a){
var kvArr=a.split('=');
返回{key:kvArr[0],value:kvArr[1]};
});
}

警报(JSON.stringify(convertString({one=Print,two=Email,three=Download,three=Send to Cloud}))问题出在哪里?显示到目前为止您已经尝试了什么?ie8中不支持.reduce()的可能重复项。是否有其他替代方案this@user3044552:检查polyfill: