json - 错误 TS2339 : Property 'json' does not exist on type 'Object'

标签 json angular object

在“task.service.ts”文件中我有:

getBooks(): Observable<Book[]> {
    return this.http.get('http://localhost:3000/books')
        .map((res) => res.json());
}

我收到消息:“ map ”不存在。所以,我在顶部添加了: import 'rxjs' 现在我收到一条错误消息: "**

error TS 2339: Property JSON does not exist on type 'Object'

**。”

我做错了什么?我忘记了什么?

最佳答案

使用 HttpClient,您不需要 map(res => res.json())

 getBooks(): Observable<Book[]> {
    return this.http.get<Book[]>('http://localhost:3000/books');
  }   

关于json - 错误 TS2339 : Property 'json' does not exist on type 'Object' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48650010/

相关文章:

javascript - 如何从 JSON 返回嵌套在对象中的嵌套 JavaScript 数组的属性值?

java - C 中的 JSON 模式代码生成

java 和 json jackson 属性 - 运行时的不同类型

angular - 在 Angular 模板中渲染 Observable 对象属性

由于某种原因没有出现 Angular 对话窗口

java - jackson 不会忽略未注释的字段

Angular 2 - Angularfire 2 身份验证状态

javascript - 如何打印 JSON 字符串的嵌套对象的值?

Java:找不到符号:变量对象

objective-c - Objective-C 和 Swift 之间的 UserDefaults