【发布时间】:2017-06-17 17:40:56
【问题描述】:
我有一个这样的 json 对象:
{path: "images/125/17062017/home.jpg"}.它来自rest api。
我想得到这条路径'images/125/17062017/home.jpg'。我需要
将该路径存储在字符串变量中。我试过这样。
JSON.parse(response).path,response.path。但是这些方法都行不通。
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吗? -
不工作。我试过这种方式
-
有什么问题?你能提供一个plnker吗?
-
@SathishKotha 我的解决方案是否有效或需要更多帮助
标签: javascript json angular typescript