布尔值是有效的JSON吗 [英] Are booleans valid JSON

查看:457
本文介绍了布尔值是有效的JSON吗的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么有些JSON验证器将布尔值标记为无效JSON,而另一些则将其标记为有效?也就是说,只有truefalse值(无对象).

Why do some JSON validators flag a boolean value as invalid JSON, and others as valid? That is, just true or false values (no object).

有效:

  • http://jsonlint.com/
  • http://codebeautify.org/jsonvalidator

无效:

推荐答案

您链接到的验证器根据true存在的JSON字符串验证为无效. org/html/rfc4627"rel =" noreferrer> RFC 4627 ,它指示JSON字符串的根是数组或对象:

The validator you link to validates the JSON string existing of a mere true as invalid according to RFC 4627, which dictates that the root of a JSON string is to be an array or object:

JSON文本是序列化的对象或数组.

A JSON text is a serialized object or array.

 JSON-text = object / array

根据该RFC ,未包装的值(例如true"foo"42)不是JSON .

An unwrapped value such as true or "foo" or 42 is not JSON according to that RFC.

可以验证的其他RFC RFC 7159 认为以上示例有效,因为它不会将JSON文本限制为对象或数组,但还允许 values :

The other RFC it can validate against, RFC 7159, deems the above examples valid as it does not constrain a JSON text to objects or arrays, but also allows values:

JSON值必须是对象,数组,数字或字符串,或者是以下之一 以下三个文字名称:

A JSON value MUST be an object, array, number, or string, or one of the following three literal names:

 false null true

由于前者(RFC 4627)已被后者(RFC 7159)淘汰,因此true 有效的JSON字符串.

And because the former (RFC 4627) is obsoleted by the latter (RFC 7159), true is a valid JSON string.

这篇关于布尔值是有效的JSON吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆