English 中文(简体)
最佳做法 - Json Parsing 中字符串与输入Stream (使用 gson)
原标题:Best Practice - String vs InputStream in Json Parsing (using gson)

在 Json/Gson 上阅读教程时,我注意到大多数人都倾向于以字符串的形式下载文件,然后通过 JSON 分析字符串。 然而,大多数 XML 教程都更喜欢直接与输入Stream 进行解析。

为什么两者有区别?什么是最佳做法/它甚至有区别?

问题回答

XML 用户学到的教训是,记忆中的大型对象树可以占用许多记忆。

JSON 剖析树的内存并不比 XML 少,但通常比较简单。 与 GSON JsonObb 对象相比, XML DOM 相当有特色。 GSON (我不知道) 可能(类似于 XML 的 SAX ) 使用只装载所需内容的流解分析器(类似于 XML 的 SAX ) 。

但我想说的是,我们从那时起就学到了。JSON通常以字符串的形式被加载的原因包括:解剖员效率更高,在大多数情况下需要的功能比完整的DOM要少,硬件更强大,JSON文件通常更短,程序员更懒惰。

说到这里,当我意识到我不得不以复杂的方式与JSON数据组合作时,我找到了这个职位,这些数据组太大,无法有效地储存在一个字符串中。你不应该这样做,但是我很感激JsonParser.parse () 有个也可以使用输入Stream的功能。





相关问题
Simple JAVA: Password Verifier problem

I have a simple problem that says: A password for xyz corporation is supposed to be 6 characters long and made up of a combination of letters and digits. Write a program fragment to read in a string ...

Case insensitive comparison of strings in shell script

The == operator is used to compare two strings in shell script. However, I want to compare two strings ignoring case, how can it be done? Is there any standard command for this?

Trying to split by two delimiters and it doesn t work - C

I wrote below code to readin line by line from stdin ex. city=Boston;city=New York;city=Chicago and then split each line by ; delimiter and print each record. Then in yet another loop I try to ...

String initialization with pair of iterators

I m trying to initialize string with iterators and something like this works: ifstream fin("tmp.txt"); istream_iterator<char> in_i(fin), eos; //here eos is 1 over the end string s(in_i, ...

break a string in parts

I have a string "pc1|pc2|pc3|" I want to get each word on different line like: pc1 pc2 pc3 I need to do this in C#... any suggestions??

Quick padding of a string in Delphi

I was trying to speed up a certain routine in an application, and my profiler, AQTime, identified one method in particular as a bottleneck. The method has been with us for years, and is part of a "...

热门标签