【问题标题】:Convert the http response from JSON objects to Typescript class将来自 JSON 对象的 http 响应转换为 Typescript 类
【发布时间】:2017-09-13 02:05:43
【问题描述】:

我在后端运行了一个 spring boot web api,我试图从一个 angular 2 webApp 中使用它,HTTP 响应如下所示

我要做的是将作为响应接收到的 JSON 对象转换为定义的 Typescript 类,以便我可以在我的应用程序中使用

【问题讨论】:

  • 请不要发布您的代码截图。相反,添加一个最小的、可测试的示例或 jsfiddle、codepen 等来演示问题。

标签: json spring-boot angular2-services


【解决方案1】:

Angular 2 使用订阅方法。试试这个:

this.http.get('https://www.reddit.com/r/gifs/new/.json?limit=10').map(res => res.json()).subscribe(data => {
    this.posts = data.data.children;
});

用于 Ionic 2 演示:https://www.joshmorony.com/using-http-to-fetch-remote-data-from-a-server-in-ionic-2/

【讨论】:

    猜你喜欢
    • 2018-11-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-22
    • 2018-03-26
    • 1970-01-01
    • 2017-10-17
    • 2014-05-17
    相关资源
    最近更新 更多