小编Mfr*_*ied的帖子

Angular - 将 HAL 转换为 JSON

以下服务从 REST 服务中提取类别对象,并以 HAL 格式返回它们。现在我尝试将该响应转换为 JSON。为此,我搜索并尝试了不同的解决方案,例如chariotsolutions等。有些是基于“@angular/http”的响应,该响应已被弃用并且我无法工作。

我该如何进行转换?

import { Injectable } from '@angular/core';
import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Observable } from 'rxjs/Rx';
import { of } from 'rxjs/observable/of';
import 'rxjs/Rx';
import 'rxjs/add/operator/map';

import { Category } from './category';

@Injectable()
export class CategoryService {

  private categoriesUrl = 'http://localhost:8080/account/categories';

  constructor(private http: HttpClient) { }

  getCategories(): Observable<Category[]> {
    return this.http.get<Category[]>(this.categoriesUrl);
  }

}
Run Code Online (Sandbox Code Playgroud)

HAL 响应

{
  "_embedded": {
    "categories": [
      {
        "id": 1,
        "name": "hardware",
        "description": "comprises …
Run Code Online (Sandbox Code Playgroud)

json hal-json angular

2
推荐指数
1
解决办法
3176
查看次数

标签 统计

angular ×1

hal-json ×1

json ×1