是的,我知道有很多关于将对象转换为json的帖子,但我的问题更具体。
说我从api调用一些数据,响应是一个看起来像这样的对象
{ date: ..., value: ..., useless-info: ..., useless-info: ... }现在我知道我可以做这个JSON.stringify(returnedobject);
所以我得到新形成的JSON ..
{ "date": ..., "value": ..., "useless-info": ..., "useless-info": ... }现在我想要在我新建立的json中成为"date"和"value"并且删除useless-info甚至有可能吗?
任何帮助,将不胜感激!
Yes I know there are heaps of posts about converting objects to json but my question is more specific..
Say Im calling some data from an api and the response is an object that looks like this
{ date: ..., value: ..., useless-info: ..., useless-info: ... }now I know I can do this JSON.stringify(returnedobject);
so I get the newly formed json..
{ "date": ..., "value": ..., "useless-info": ..., "useless-info": ... }now all I want in my newly formed json to be the "date" and "value" and remove the useless-info is this even possible?
any help would be appreciated!
最满意答案
你可以用你想要的数据创建一个新对象,或者删除你不需要的字段:
const someReturn = { date: ..., value: ..., badstuff: ... } const goodObj = { date: someReturn.date, value: someReturn.value }或者删除字段,您可以调用delete someReturn.badstuff
You can either create a new object with the data you want, or delete the fields you don't need:
const someReturn = { date: ..., value: ..., badstuff: ... } const goodObj = { date: someReturn.date, value: someReturn.value }Or to delete fields you can just call delete someReturn.badstuff
更多推荐
发布评论