【问题标题】:JSON string gets parsed correctly in Postman but the same fails in JavaScriptJSON 字符串在 Postman 中被正确解析,但在 JavaScript 中同样失败
【发布时间】:2017-09-10 21:45:36
【问题描述】:

这是我传递给 POST 请求的 JSON 字符串:

  var data =    {
          "location": {
            "value": {
              "href": "http://localhost:8080/restful/objects/businessentities.Location/47"
            }
          },
          "asset": {
            "value": {
              "href": "http://localhost:8080/restful/objects/businessentities.Asset/36"
            }
          }
  }

AngularJS 资源代码为:

var AuditItemCreate = $resource(
  apiUrl +   '/restful/services/domainapp.dom.BusinessEntities.AuditItemMenu/actions/create/invoke/');

var a2 = new AuditItemCreate();
a2.$save(data)
     .then(function(res)  { console.log("success") })
     .catch(function(req) { console.log("error saving obj: " + JSON.stringify(req, null, 4)); })

但是我收到服务器响应 422(无法处理的实体)错误:

error saving obj: {
    "data": {
        "asset": {
            "value": "{\"value\":{\"href\":\"http://localhost:8080/restful/objects/businessentities.Asset/36\"}}",
            "invalidReason": "Expected a link (because this object's type is not a value) but found no 'href'"
        },
        "location": {
            "value": "{\"value\":{\"href\":\"http://localhost:8080/restful/objects/businessentities.Location/47\"}}",
            "invalidReason": "Expected a link (because this object's type is not a value) but found no 'href'"
        },
        "x-ro-invalidReason": "Mandatory"
    },

同样的 JSON 字符串在 Postman 中使用时可以成功运行。

【问题讨论】:

    标签: javascript angularjs json isis


    【解决方案1】:

    我能够解决这个问题——通过使用自己的资源类,而不是它的资源实例。

    【讨论】:

      猜你喜欢
      • 2020-04-23
      • 1970-01-01
      • 1970-01-01
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 2019-11-07
      • 1970-01-01
      • 2011-12-24
      相关资源
      最近更新 更多