由于格式错误而导致错误

Promise error because of bad format

我像这样创建了一个新的 RestAdapter。

import DS from 'ember-data';

export default DS.RESTAdapter.extend({
  namespace: 'api',
  host: 'http://localhost:8081'
});

如果我查看网络调用,api 被正确调用并且 returns 此数据。

{
      "environments": [
        {
          "Id": 1,
          "LocalePath": "C:\XML_DEPOT",
          "Name": "Acceptation 1",
          "RemotePath": "D:\XML_DEPOT",
          "DatabaseServerName": "somedata",
          "DatabaseName": "somedata",
          "Port": 60903
        },
        {
          "Id": 2,
          "LocalePath": "bob",
          "Name": "Acceptation 2",
          "RemotePath": "bob",
          "DatabaseServerName": "somedata\somedata",
          "DatabaseName": "somedata",
          "Port": 60904
        }
    ]
}

然后我收到一条错误消息说

Assertion Failed: normalizeResponse must return a valid JSON API document

但据我所知,适配器不是 JSONAPIAdapter,所以它不应该尝试序列化它有一个 jsonapi ??

Ember 自版本 1.13 起,数据在内部使用 JSON Api 规范作为 DS.RestAdapter "is used to normalize a payload from the server to a JSON-API Document."[=14= 的 described in release notes. normalizeResponse 方法]

您的负载看起来不像 ember 数据 RestAdapater 默认情况下除外。 RestAdapter 需要驼峰式键,但你的是驼峰式。您必须自定义序列化程序 keyForAttribute 方法才能使其正常工作。