这是我的JSON文件的样子:
{
"responseCode": 200,
"responseMessage": "" ,
"details": "{\"id\":1,\"name\":\"sss\",\"status\":\"status 1\",\"active\":true,\"createdAt\":\"Dec 4, 2019, 4:21:46 PM\",\"modifiedAt\":\"Dec 5, 2019, 10:21:09 AM\",\"description\":\"daddddddddddddd\",\"imagePath\":\"imagepath 1\",\"viewCount\":133,\"important\":1}",
"timestamp": 0
}
TS文件:
ngOnInit() {
this.blog.getBlog(this.id).subscribe((data: {}) => {
this.blogData = JSON.parse(data['details']);
})
}
updateBlog() {
if(window.confirm('Are you sure, you want to update?')){
this.blog.UpdateBlog(this.id, this.blogData).subscribe(data => {
this.router.navigate(['/home/blogger'])
})
}
}
服务文件:
UpdateBlog(id,blog): Observable<Blog> {
let body = JSON.stringify(blog);
console.log(blog)
return this.http.put<Blog>('blog/' + id, body, this.httpOptions)
.pipe(
retry(1),
catchError(this.handleError)
)
}
我可以执行诸如获取,删除和创建之类的操作,但无法将值更新为以下JSON格式。
下面是send选项下的邮递员代码:
PUT /api/blog/3 HTTP/1.1
Host: 13.234.196.102:8080
Content-Type: application/json
Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJwcmF2aWwiLCJpYXQiOjE1NzU1NDk2NTEsImV4cCI6MTU3NTYzNjA1MX0.j9FBDckN2jfi3-LU5coVGRZfW3wQEBnGpF4MAZ2u_pH6MRdA2KU_xrZTvb1ki9DWTydQ8YTrAgYg2uMkKktn9A
User-Agent: PostmanRuntime/7.19.0
Accept: */*
Cache-Control: no-cache
Postman-Token: 7e19e28c-6dde-42e8-b9f2-c1546eb65825,82753b69-39ad-48a5-b5fd-552e07008594
Host: 13.234.196.102:8080
Accept-Encoding: gzip, deflate
Content-Length: 160
Connection: keep-alive
cache-control: no-cache
{
"name": "sss",
"description": "Thsh",
"imagePath": "imagepath 1",
"status": "status 1",
"active": true
}