是否有用于 JSON 的流式 API?

问题描述:

DOM 是解析 JSON 的唯一方法吗?

Is DOM the only way to parse JSON?

某些 JSON 解析器确实提供了增量(流式")解析器;对于 Java,至少以下来自 json.org 页面的解析器提供了这样的接口:

Some JSON parsers do offer incremental ("streaming") parser; for Java, at least following parsers from json.org page offer such an interface:

  • Jackson (pull interface)
  • Json-simple (SAX-style push interface)

(除了另一个答案提到的Software Monkey的解析器)

(in addition to Software Monkey's parser referred to by another answer)

实际上,很多 JSON 解析器不提供这种简单的低级接口有点奇怪——毕竟,他们已经需要实现低级解析,所以为什么不公开它.

Actually, it is kind of odd that so many JSON parsers do NOT offer this simple low-level interface -- after all, they already need to implement low-level parsing, so why not expose it.

编辑(2011 年 6 月):Gson 也有自己的 流 API(带有gson 1.6)

EDIT (June 2011): Gson too has its own streaming API (with gson 1.6)