开发者

The best way to provide a JSON InputStream

开发者 https://www.devze.com 2023-03-15 16:02 出处:网络
In different languages I need to provide users with a stream of JSON objects with an interface similar to the following:

In different languages I need to provide users with a stream of JSON objects with an interface similar to the following:

JSONObject json = stream.nextJSON();

Since it is a stream, each call will block 开发者_StackOverflow社区until a full object has been retrieved. This means it makes no sense to try and encapsulate each JSON object inside a big array. An extra layer of structure and processing has to be added to the stream.

I have thought of two options:

  1. Segmenting the stream with the null-termination character.
  2. Writing a primitive parser that understand JSON scope so can detect the end of an object.

Each of the above have a number of potential issues to discuss: How will null-termination interact with the file system, socket or underlying streams in C++, Java and other languages? What edge cases would we need to take in to account when parsing? (different types of quote symbol might confuse a parser, for example). Furthermore, there might be alternatives to the two above.

So the question is: What is the best way to provide a JSON InputStream?


Well Google already thought about it apparently:

http://sites.google.com/site/gson/streaming

0

精彩评论

暂无评论...
验证码 换一张
取 消