json阵列与null
以下是解析以验证PUT请求主体的JSON:
{
"requestKey": "whatever",
"shoppingList": []
}
作为测试的一部分,我们看到了另一种情况,这也是有效的JSON:
{
"requestKey": "whatever",
"shoppingList": [null]
}
[]
表示空的购物列表。 [null]
表示什么?
[null]
与[]
有何不同?对于购物清单
Below is the JSON that is parsed to validate PUT request body:
{
"requestKey": "whatever",
"shoppingList": []
}
As part of testing, we are seeing another scenario coming, which is also a valid JSON:
{
"requestKey": "whatever",
"shoppingList": [null]
}
[]
signifies empty shopping list. What does [null]
signify?
How [null]
different from []
? for shoppingList
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
null
在这种情况下,如 rfc 7159 购物清单是一个包含一个原始空值的数组。至少从语义上讲,它应该屈服(源示例在Java中):
而空数组应屈服:
这正是您在当前版本的Google Chrome中看到的行为:
null
in this case and as referenced in RFC 7159 means that the shoppingList is an array containing one primitive null value.At least semantically it should yield in (Source example is in Java):
Whereas an empty array should yield in:
Which is exactly the behaviour you see in the current version of Google Chrome: