JSONAPI布尔属性

时间:2016-07-19 16:05:51

标签: specifications json-api

使用JSONAPI时,如何处理布尔属性?

例如:

gsub("(A<[^>]+>B)", "<b>\\1</b>", a)
[1] "<b>A<br/>B</b><br/>C"

{
    "type": "motors",
    "id": "1",
    "attributes": {
      "name": "V8",
      "working": "true"
    }
}

此外,我认为这是更好的解决方案,但不适用于官方规范:

{
    "type": "motors",
    "id": "1",
    "attributes": {
      "name": "V8",
      "working": "1"
    }
}

1 个答案:

答案 0 :(得分:1)

前两个示例代表strings,最后一个示例代表JSON上的a booleanhttp://www.json.org/

来自规范:

值可以是string in double quotesnumbertruefalsenullan object或{{ 1}}。这些结构可以嵌套。

如果您真的想要an array,请使用最后一个示例。

a boolean对此没有任何说明,因为规范本身位于JSON:API之上(继承所有JSON规范)

相关问题