Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我正在使用反序列化字符串JSON.parse。大多数时候,我有一个内容对象序列化为一个字符串,并JSON.parse在该字符串上工作,但在某些情况下,我想向 发送一个最小输入JSON.parse,其结果将被丢弃。当我发送""like:JSON.parse("")时,它返回一个错误:unexpected token at '""'。我违反的 JSON 规范的限制是什么,我可以发送什么替代的最小字符串JSON.parse?
JSON.parse
""
JSON.parse("")
unexpected token at '""'
阅读 Musa 提供链接的 JSON 规范,可以字符串化并发送到 JSON 的最小对象似乎是:
[null]
或类似的东西。或者,在字符串化的形式中,它将是:
"[null]"
我会发送null,因为这代表“无”。
null
require 'json' nil.to_json #=> "null"