我有一個JSON對象是這樣的: {path: "images/125/17062017/home.jpg"}
。它的從REST API的到來。 我想要得到這個路徑'images/125/17062017/home.jpg'
。我需要 將該路徑存儲在字符串變量中。我試過這樣。 JSON.parse(response).path
,response.path
。但是這些方法不起作用。如何將JSON值轉換爲角度4中的字符串?
fileChange(event: any) {
const fileList: FileList = event.target.files;
if(fileList.length > 0) {
let file: File = fileList[0];
this.fileUploadService.saveOwnImageFile(file)
.subscribe((response: any) =>{
console.log(response); // response = {path:'images/125/17062017/home.jpg'}
let value = JSON.parse(response); // getting error here
console.log(value);
});
}
}
response.json()? –
這是爲什麼?不能只寫'let value = response.path'? –
無法正常工作。我試過那種方式 –