如何将JSON响应转换为数组JavaScript
我有来自API的JSON响应:
[
{
"obj_Id": 66,
"obj_Nombre": "mnu_mantenimiento_de_unidades",
"obj_Descripcion": "Menu de acceso a Mantenimiento de Unidades"
},
{
"obj_Id": 67,
"obj_Nombre": "mnu_vehiculos_en_reparacion",
"obj_Descripcion": "Menu de acceso a Reparacion de Unidades"
},
{
"obj_Id": 68,
"obj_Nombre": "mnu_RTO",
"obj_Descripcion": "Menu de acceso a RTO"
}
]
我有此功能来提出请求并转换响应:
async obtenerPermisos() {
var respuesta = "";
var obj = {
idUsuario: JSON.parse(sessionStorage.getItem("Codigo")),
contraseña: this.passwordEncriptado,
};
this.url = this.urlBase + "usuario/obtenerPermisos";
respuesta = await this.$http.post(this.url, obj).then((response) => {
const respuesta1 = JSON.parse(respuesta);
sessionStorage.setItem("Permisos", respuesta1);
response.data;
});
console.log("Los permisos del usuario son: ");
console.log(respuesta);
console.log("El tipo de parametro es: " + typeof respuesta);
sessionStorage.setItem("Permisos", respuesta);
this.$router.push({ name: "sideBar" });
location.reload();
},
但是我得到此错误:
我该如何解决?
I have this json response from a api:
[
{
"obj_Id": 66,
"obj_Nombre": "mnu_mantenimiento_de_unidades",
"obj_Descripcion": "Menu de acceso a Mantenimiento de Unidades"
},
{
"obj_Id": 67,
"obj_Nombre": "mnu_vehiculos_en_reparacion",
"obj_Descripcion": "Menu de acceso a Reparacion de Unidades"
},
{
"obj_Id": 68,
"obj_Nombre": "mnu_RTO",
"obj_Descripcion": "Menu de acceso a RTO"
}
]
I have this function to make the request and convert the response:
async obtenerPermisos() {
var respuesta = "";
var obj = {
idUsuario: JSON.parse(sessionStorage.getItem("Codigo")),
contraseña: this.passwordEncriptado,
};
this.url = this.urlBase + "usuario/obtenerPermisos";
respuesta = await this.$http.post(this.url, obj).then((response) => {
const respuesta1 = JSON.parse(respuesta);
sessionStorage.setItem("Permisos", respuesta1);
response.data;
});
console.log("Los permisos del usuario son: ");
console.log(respuesta);
console.log("El tipo de parametro es: " + typeof respuesta);
sessionStorage.setItem("Permisos", respuesta);
this.$router.push({ name: "sideBar" });
location.reload();
},
but i get this error:
how can i resolve it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
返回的数据不会传递给json.parse()
The data being returned is not being passed to JSON.parse()