Convert Object holding arrays to JSON
I have an object which contain multiple arrays like in the following screenshot:
and I would like to convert it into this object:
{ "Manifacture": "Samsung", "Model": "Ipad 2" }
in order to use the data in bootstrap table.
When using stringify
, I'm getting the following:
"{"Manifacture":[{"id":2,"name":"Samsung"}],"Model":[{"id":1,"name":"Ipad 2"}]"}"
which is different than what I need.
Is it possible?
你可以使用普通的javascript处理对象。
for (var key in obj) {
obj[key] = obj[key][0].name
}
JSON.stringify(obj)
链接地址: http://www.djcxy.com/p/46292.html
下一篇: 将保存数组的对象转换为JSON