发布到 orion 让我“属性必须是 JSON 对象”

问题描述

我将这个发送给 Orion:

curl --location --request POST 'http://xx.xx.xx.xx:1026/ngsi-ld/v1/entities/' \
--header 'link: <https://smartdatamodels.org/context.jsonld>; rel="http://www.w3.org/ns/json-ld#context"; type="application/ld+json"' \
--header 'Content-Type: application/json' \
--data-raw '{
    "id": "urn:ngsi-ld:Device:01","type": "Device","description": "L9A","category": {
        "value": ["sensor"]
    },"serialNumber": {
        "value": "38479144"
    },"controlledProperty": {
        "value": ["Water Supply"]
    },"owner": {
        "value": ["Me"]
    },"location": {
        "type": "Point","coordinates": [20.200416,30.261837]
    }
}'

我明白了:

错误 400:错误请求

{
    "type": "https://uri.etsi.org/ngsi-ld/errors/BadRequestData","title": "Attribute must be a JSON object","detail": "description"
}

我通过 json 对象验证并且通过了。我做错了什么?

解决方法

仔细查看您的错误消息,尤其是:

detail": "description"

这是不是 JSON 对象的属性的名称:

"description": "L9A"

如果您将其更改为:

"description": {
  "type": "Property","value": "L9A"
}

那部分应该没问题。

但是,您的所有属性似乎都缺少 type 成员。 您需要将 "type": "Property" 添加到所有这些中,除了 GeoProperty 的“位置”:

"location": {
  "type": "GeoProperty","value": {
    "type": "Point","coordinates": [20.200416,30.261837]
  }
}

也许花一些时间阅读 NGSI-LD 规范? https://www.etsi.org/deliver/etsi_gs/CIM/001_099/009/01.04.02_60/gs_CIM009v010402p.pdf