[英]Angular5 HTTPclient get issue with nested json
HttpClient.get in Angular 5 is not returning data if data is in a nested json format. 如果数据采用嵌套json格式,则Angular 5中的HttpClient.get不会返回数据。 The code below works for non-nested json data.
以下代码适用于非嵌套json数据。 Would you please let me know if I miss anything or what would be a way to get the data?
如果我错过了任何事情,或者将是一种获取数据的方式,请告诉我吗?
Code: 码:
import { HttpClient, HttpHeaders, HttpErrorResponse } from '@angular/common/http';
export class ReportService {...
searchByUser(userUrl: string): Observable<any> {
console.log('userUrl', userUrl);
return this.httpClient
.get(userUrl, { responseType: 'json' })
.catch((error: HttpErrorResponse) => {
return Observable.throw(error.status)
});
}
}
import { ReportService } from '../report.service';
this.reportService.searchByUser(userUrl).subscribe(data => {
console.log("Data :", data);
});
Nested JSON Sample Data returned by the userUrl: userUrl返回的嵌套JSON示例数据:
[
{
"userId": "JX",
"location": "CHANTILLY, XX",
"fullName": "SMITH, JX L",
"userType": "P",
"userStatusDesc": "Active",
"occupationInfo": {
"occupationTitle": "HR GENERALIST HQ"
},
"miscInfo": {
"rankingPoints": 15,
"searchTermCount": 1
}
}
]
It looks like the issue was not with the HttpClient or nested JSON. 看起来问题不在于HttpClient或嵌套JSON。 I was able to have it working with the same JSON generated locally.
我能够使用本地生成的相同JSON。 And when I deployed the code it worked with the JSON generated under the same proxy.
当我部署代码时,它可以使用在同一代理下生成的JSON。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.