您如何在JSON API中表示无穷大? [英] How do you represent infinity in a JSON API?
问题描述
在JSON API中表示无穷大的最佳方法是什么?例如免费阅读本月的文章(某些订阅将是有限数量,高级订阅将是无限数量).
What is the best way to represent infinity in a JSON API? e.g. free to read articles for this month (this will be a finite number on some subscriptions and infinite on the premium subscription).
针对此用例返回null
还是扩展 JSON并使用javascript的Infinity
值是更好的主意吗?后者似乎更合适,但我从未见过执行此操作的API示例.
Is it a better idea to return null
for this use case or to extend JSON and use the javascript's Infinity
value? The latter seems more appropriate, but I've never seen an example of an API which does this.
如果有人有任何表示无穷大的公共Web API的示例,那也很酷.
It would also be cool if anyone had any examples of public Web APIs which represent infinity.
推荐答案
我将包括一个限制"字段,该字段仅在确实存在限制时存在:
I would include a field "limit", which only exists when there really is a limit:
当用户剩下40个时:
{
"yourdata":"",
"limit": 40
}
当用户具有无限访问权限时,将其删除,这意味着没有限制:
when the user has unlimited access remove it, meaning there is no limit:
{
"yourdata":""
}
这篇关于您如何在JSON API中表示无穷大?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!