我在NextJs中创建了一个API,NextResponse将根元素添加到生成的JSON中。
下面是API的返回值:
return NextResponse.json({result},{ status: 200 });
字符串
下面是调用的原始结果。
[{"id":11,"first_name":"test2","last_name":"employee","job_title":"test job","employeeStrengths":[{"id":65,"order":1,"strength":{"title":"Achiever"}},{"id":580,"order":2,"strength":{"title":"Ideation"}},{"id":581,"order":3,"strength":{"title":"Futuristic"}},{"id":582,"order":4,"strength":{"title":"Relator"}},{"id":583,"order":5,"strength":{"title":"Learner"}},{"id":66,"order":6,"strength":{"title":"Competition"}},{"id":579,"order":7,"strength":{"title":"Strategic"}},{"id":578,"order":8,"strength":{"title":"Analytical"}}]}]
型
以下是API(NextResponse)返回的内容:
{
"result": [
{
"id": 11,
"first_name": "test2",
"last_name": "employee",
"job_title": "test job",
"employeeStrengths": [
{
"id": 65,
"order": 1,
"strength": {
"title": "Achiever"
}
},
{
"id": 580,
"order": 2,
"strength": {
"title": "Ideation"
}
},
{
"id": 581,
"order": 3,
"strength": {
"title": "Futuristic"
}
},
{
"id": 582,
"order": 4,
"strength": {
"title": "Relator"
}
},
{
"id": 583,
"order": 5,
"strength": {
"title": "Learner"
}
},
{
"id": 66,
"order": 6,
"strength": {
"title": "Competition"
}
},
{
"id": 579,
"order": 7,
"strength": {
"title": "Strategic"
}
},
{
"id": 578,
"order": 8,
"strength": {
"title": "Analytical"
}
}
]
}
]
}
型
我想去掉根元素“result:“
任何见解都值得赞赏。
1条答案
按热度按时间js5cn81o1#
不要破坏它。
字符串
还有一件事,
status: 200
是默认值。你可以把它去掉。型