Github API 响应复制到 javascript 对象 Angular 应用程序

使用github端点https://api.github.com/users/,我想将json响应复制到具有相同键的javascript对象中,有没有比逐行使用oject变量赋值更好的方法? ?


示例 json 响应


{

    "login": "imukunya",

    "name": null,

    "company": null,

    "blog": "",

    "location": null,

    "email": null,

    "hireable": null,

    "bio": null,

    "twitter_username": null,

    "public_repos": 19,

    "public_gists": 0,

    "followers": 0,

    "following": 0,

    "created_at": "2020-04-28T07:14:15Z",

    "updated_at": "2020-11-06T04:20:24Z"

}

JavaScript 对象


userProfile = {

    

    "login": "",

    "name": ,

    "company": ,

    "blog": "",

    "location":"" ,

    "email": "",

    "hireable": "",

    "bio": "",

    "twitter_username": "",

    "public_repos": 0,

    "public_gists": 0,

    "followers": 0,

    "following": 0,

    "created_at": "",

    "updated_at": ""

}


青春有我
浏览 107回答 1
1回答

蝴蝶刀刀

使用扩展运算符。userProfile = { ...userProfile, ...jsonResponse };
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript