本文整理汇总了TypeScript中json2typescript.JsonConvert.deserialize方法的典型用法代码示例。如果您正苦于以下问题:TypeScript JsonConvert.deserialize方法的具体用法?TypeScript JsonConvert.deserialize怎么用?TypeScript JsonConvert.deserialize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json2typescript.JsonConvert
的用法示例。
在下文中一共展示了JsonConvert.deserialize方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1:
.pipe(map(user => {
// login successful if there's a jwt token in the response
if (user && user.token) {
// store user details and jwt token in local storage to keep user logged in between page refreshes
const mappedUser = this.jsonConvert.deserialize(user, User);
localStorage.setItem('currentUser', JSON.stringify(mappedUser));
this.currentUserSubject.next(mappedUser);
}
return user;
}));
示例2: updateUserLocal
updateUserLocal(user: User) {
const currentUser = this.authenticationService.currentUserValue as User;
if (!!currentUser && !!user) {
const mappedUser = this.jsonConvert.deserialize(user, User);
currentUser.name = mappedUser.name !== undefined && mappedUser.name !== null ? mappedUser.name : currentUser.name;
currentUser.bio = mappedUser.bio !== undefined && mappedUser.bio !== null ? mappedUser.bio : currentUser.bio;
currentUser.company = mappedUser.company !== undefined && mappedUser.company !== null ? mappedUser.company : currentUser.company;
currentUser.location = mappedUser.location !== undefined && mappedUser.location !== null ? mappedUser.location : currentUser.location;
currentUser.email = mappedUser.email !== undefined && mappedUser.email !== null ? mappedUser.email : currentUser.email;
currentUser.username = mappedUser.username !== undefined && mappedUser.username !== null ? mappedUser.username : currentUser.username;
currentUser.active = mappedUser.active !== undefined && mappedUser.active !== null ? mappedUser.active : currentUser.active;
localStorage.setItem('currentUser', JSON.stringify(currentUser));
this.authenticationService.refreshLocalData();
}
}
示例3:
.pipe(map(user => {
return this.jsonConvert.deserialize(user, User);
}));