[英]Change structure JSON with Javascript
我有以下结构,我的网络服务的响应:
{"rows":[
{"1","A Time to Kill", "John Grisham", "100"},
{"2","A Time to Kill", "John Grisham", "200"},
{"3","A Time to Kill", "John Grisham", "500"}
]}
我需要用下一个改变结构:
{rows:[
{ id:1, data: ["A Time to Kill", "John Grisham", "100"]},
{ id:2, data: ["Blood and Smoke", "Stephen King", "1000"]},
{ id:3, data: ["The Rainmaker", "John Grisham", "-200"]}
]
}
有任何想法吗?
提前致谢。
您可以使用其他键然后使用旧键并使用所需结构构建一个新对象。
var data = { rows: [{ Id_Tipo_Documento: "1", Nombre_Documento: "Dni" }, { Id_Tipo_Documento: "2", Nombre_Documento: "Carnet de Extranjería" }, { Id_Tipo_Documento: "3", Nombre_Documento: "Pasaporte" }] }, result = { rows: data.rows.map( ({ Id_Tipo_Documento, Nombre_Documento }) => ({ id: Id_Tipo_Documento, data: [Nombre_Documento] }) ) }; console.log(result);
.as-console-wrapper { max-height: 100% !important; top: 0; }
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.