首页 > 技术文章 > angular4读取JSON数据

914556495wxkj 2017-09-13 22:56 原文

直接上代码:

确保json是可访问的

http://localhost:54843/dist/appsettings.json文件

{
"Logging": {
"IncludeScopes": false,
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
},
"freetrial": {
"id": "01",
"imgurl": "images/1.jpg",
"status": "0"
}
}

http请求:

this.http.get(url).subscribe(data => {
console.log(data);
let url = data.json().Logging;
let urlss = data.json().Logging.IncludeScopes;
let xx = data.json().freetrial.id;
let sTaskName = data.json()["Logging"];

});

推荐阅读