我有一个JavaScript对象:转换逗号分隔的JavaScript对象值阵列
Object { [email protected]=80, [email protected]=119, [email protected]=240}
我想这个对象转换为一个数组一样:
[{ "[email protected]"="80"}, {"[email protected]"="119"}, {"[email protected]"="240"}]
任何帮助,将不胜感激..
我有一个JavaScript对象:转换逗号分隔的JavaScript对象值阵列
Object { [email protected]=80, [email protected]=119, [email protected]=240}
我想这个对象转换为一个数组一样:
[{ "[email protected]"="80"}, {"[email protected]"="119"}, {"[email protected]"="240"}]
任何帮助,将不胜感激..
您可以将对象的属性映射到数组(使用Object.keys()和Array.prototype.map()):
var obj = {
'[email protected]': 80,
'[email protected]': 119,
'[email protected]': 240
};
var result = Object.keys(obj).map(function(key) {
var arrItem = {};
arrItem[key] = String(obj[key]);
return arrItem;
});
console.log(result);
奇怪的对象...在其代码表示中显示您的对象 – RomanPerekhrest
我使用JSOn Api将hashmap转换为JSON响应。 –
Nir
我想你正在使用Java与Hashmap,JSONArray,JSONObject类 – RomanPerekhrest