JSONAPI 布尔属性
JSONAPI boolean attributes
当您使用 JSONAPI 时,您如何处理布尔属性?
例如:
{
"type": "motors",
"id": "1",
"attributes": {
"name": "V8",
"working": "true"
}
}
或
{
"type": "motors",
"id": "1",
"attributes": {
"name": "V8",
"working": "1"
}
}
此外,我认为这是更好的解决方案,但不适用于官方规范:
{
"type": "motors",
"id": "1",
"attributes": {
"name": "V8",
"working": true
}
}
前两个示例表示 strings
,最后一个示例表示 JSON (http://www.json.org/)
上的 a boolean
值
来自规范:
一个值可以是string in double quotes
,或number
,或true
,或false
,或null
,或an object
,或an array
。这些结构可以嵌套。`
如果你真的想要a boolean
那么使用最后一个例子。
JSON:API
什么都不说,因为规范本身是在 JSON
之上的(继承所有 JSON
规范)
当您使用 JSONAPI 时,您如何处理布尔属性?
例如:
{
"type": "motors",
"id": "1",
"attributes": {
"name": "V8",
"working": "true"
}
}
或
{
"type": "motors",
"id": "1",
"attributes": {
"name": "V8",
"working": "1"
}
}
此外,我认为这是更好的解决方案,但不适用于官方规范:
{
"type": "motors",
"id": "1",
"attributes": {
"name": "V8",
"working": true
}
}
前两个示例表示 strings
,最后一个示例表示 JSON (http://www.json.org/)
a boolean
值
来自规范:
一个值可以是string in double quotes
,或number
,或true
,或false
,或null
,或an object
,或an array
。这些结构可以嵌套。`
如果你真的想要a boolean
那么使用最后一个例子。
JSON:API
什么都不说,因为规范本身是在 JSON
之上的(继承所有 JSON
规范)