是否有用于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)