我有一个格式为
的json字符串var jsonData = [{"label":"Hass1(xxx_sem@hotmail.com)","value":"xxx_sem@hotmail.com"},{"label":"Hass(sxx_sem@hotmail.com)","value":"sxx_sem@hotmail.com"},{"label":"Sam(sx_sem@hotmail.com)","value":"sx_sem@hotmail.com"}]
我需要将其格式转换为这种方式
var obj = {"Hass1(xxx_sem@hotmail.com)":"xxx_sem@hotmail.com",
"Hass(sxx_sem@hotmail.com)","sxx_sem@hotmail.com"}
怎么做?
到目前为止,我已经实施了
function ConvertMeJason(jsonMe) {
var list = JSON.parse(jsonMe);
list.Object.forEach(function (obj) { /// I am getting error undefined function foreach
emptyJson.add('"' + obj.label + '"', '"' + obj.value + '"');
})
}
答案 0 :(得分:0)
这样的事情:
function convert(data) {
var obj = {};
for (var i = 0; i<data.length; i++) {
obj[data[i].label] = data[i].value;
}
return obj;
}
这是JSFiddle。