是无效的有效JSON(4个字节,别无其他) [英] Is null valid JSON (4 bytes, nothing else)

查看:78
本文介绍了是无效的有效JSON(4个字节,别无其他)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天热烈辩论:

文本流null是有效的JSON吗?

Is the text stream null valid JSON?

根据 http://www.ietf.org/rfc/rfc4627. txt?number = 4627 :

...
2. JSON语法

...
2. JSON Grammar

JSON文本是令牌序列.令牌集包括 六个结构字符,字符串,数字和三个文字 名称.

A JSON text is a sequence of tokens. The set of tokens includes six structural characters, strings, numbers, and three literal names.

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

A JSON text is a serialized object or array.

为了使文本成为有效的JSON,这应该解释为两个语句都必须为真吗?

Should this interpreted as both statements must be true in order for the text to be valid JSON?

  • http://code.google.com/p/json-framework/issues/detail?id=49 seems to indicate (at the bottom) that this is invalid.
  • http://json.parser.online.fr/ also flags this as invalid.

但是,许多其他库似乎都允许这样做,并且确实,单个有效令牌可能可能是合法的结果.

However, many other libraries seem to permit it, and indeed, it seems like a single valid token could be a legitimate result.

有明确的答案吗?

推荐答案

[注意!此答案不再正确,请参阅@niksnut的答案.]

[Note! This answer is no longer correct, see answer by @niksnut.]

是的,两个陈述都必须为真.文字令牌null是JSON . JSON文本是序列化的对象或数组,需要{}或[].

Yes, both statements must be true. The literal token null is a JSON value. A JSON text is a serialized object or array, which requires {} or [].

这篇关于是无效的有效JSON(4个字节,别无其他)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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