【发布时间】:2017-03-20 20:46:09
【问题描述】:
当您使用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
}
}
【问题讨论】:
-
我认为如果不将值括在双引号之间,您将无法逃脱; "true" 应该可以正常工作(前提是您将映射到具有适当 bool 属性的模型),并且它也比 "1" 更明确
-
jsonapi 规范没有说“属性总是像字符串?”