admin管理员组文章数量:1406949
I'm trying to make a get request to json-server to get in a nested object. But it is returning an empty response instead of the object key data.
I have gone through the documentation and there is nothing specific to the db structure that I have.
I want to filter the model array but not getting the model data.
my db.json file is
{
"data": {
"model":
[
{
"name": "BERLINGO",
"manufacturerName": "CITREON",
"id": 1
},
{
"name": "C3",
"manufacturerName": "CITREON",
"id": 2
}
]
}
}
For GET /data , I'm getting the following response.
{
"model": [
{
"name": "BERLINGO",
"manufacturerName": "CITREON",
"id": 1
},
{
"name": "C3",
"manufacturerName": "CITREON",
"id": 2
}
]
}
GET call for /data/model is giving an empty object.
{}
I'm trying to make a get request to json-server to get in a nested object. But it is returning an empty response instead of the object key data.
I have gone through the documentation and there is nothing specific to the db structure that I have.
I want to filter the model array but not getting the model data.
my db.json file is
{
"data": {
"model":
[
{
"name": "BERLINGO",
"manufacturerName": "CITREON",
"id": 1
},
{
"name": "C3",
"manufacturerName": "CITREON",
"id": 2
}
]
}
}
For GET /data , I'm getting the following response.
{
"model": [
{
"name": "BERLINGO",
"manufacturerName": "CITREON",
"id": 1
},
{
"name": "C3",
"manufacturerName": "CITREON",
"id": 2
}
]
}
GET call for /data/model is giving an empty object.
{}
Share asked Jun 13, 2019 at 14:21 ExpertNoobExpertNoob 1391 silver badge9 bronze badges 4- Where is the code for the call you are making? – basic Commented Jun 13, 2019 at 14:23
- I'm just making a GET call directly from the browser URL bar as of now to test if I'm getting the data. Eventually, I'll be doing it inside my react app with axios – ExpertNoob Commented Jun 13, 2019 at 14:24
- Is there any log at console? – Juan Diego Lozano Commented Jun 13, 2019 at 14:32
- @JDLozano yes, in the chrome netwrok tab, it has the 404 error, same in the json-server, i.e. the 404 error for the request /data/model – ExpertNoob Commented Jun 13, 2019 at 14:35
1 Answer
Reset to default 6Unfortunately, json-server
does not support such "nested value" syntax. You can GET /data
, but cannot GET /data/model
or GET /data.model
. All you can do is fetching the whole /data
object and access model
field of it.
This is already discussed in json-server
's GitHub Repo, and according to an older discussion, it seems the owner of json-server
(@typicode) does not intend to make this support.
本文标签: javascriptNot able to GET object key data in JSONSERVERStack Overflow
版权声明:本文标题:javascript - Not able to GET object key data in JSON-SERVER - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744927882a2632714.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论