我有 json 数据,我想将其转换为对象格式以进行创建操作。
json
[
{
"user": {
"id": 83,
"username": "das",
"first_name": "dsafha",
"last_name": "dfksdfk",
"email": "sasda@gmail.com",
"is_active": true,
"is_superuser": false
},
"role": "testBu"
},
{
"user": {
"id": 84,
"username": "sadfds",
"first_name": "dshhgds",
"last_name": "fsdjsl",
"email": "fdjgd@gmail.com",
"is_active": true,
"is_superuser": false
},
"role": "testeditrole"
},
{
"user": {
"id": 86,
"username": "fs",
"first_name": "efhks",
"last_name": "sofdh",
"email": "fdshk@gmail.com",
"is_active": true,
"is_superuser": false
},
"role": "testeditrole"
},
{
"user": {
"id": 87,
"username": "xz",
"first_name": "vj",
"last_name": "vkfd",
"email": "sdsl@gmail.com",
"is_active": true,
"is_superuser": false
},
"role": "testeditrole"
}
]
我试着这样做
组件.ts
let user:any = {};
user["username"] = this.user.user.email
user["first_name"] = this.user.user.first_name
user["last_name"]= this.user.user.last_name
user["email"]= this.user.user.email
this.userData["user"] = user
this.userData["role"] = this.user.role
在将数据输入输入字段后进行安慰时,我没有得到角色数据。我确实得到了其他数据。角色数据显示为空。我确实认为这是因为我在 componet.ts 中编写代码的方式导致了问题。