[QUESTION]fastjson1中的流式获取json中的数据的方式 JSONReader.startObject()在fastjson2中用什么来替代?
- Dominant language
- Java
- Stars
- 4.4k
- Forks
- 613
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 6
Description
原来在fastjson1中,因为有些json非常大,全部加载进内存会占用很大内存,所以使用流式来获取json中的数据,原来有用法如下
```
JSONReader jsonObject = new JSONReader(reader);//传入流
jsonObject.startObject();//相当于开始读整个json的Object对象。
while (jsonObject.hasNext()) {//是否有下一个k-v值
Object key = jsonObject.readObject();//获取key
Object value = jsonObject.readObject();//获取value
}
jsonObject.endObject();//结束读取
jsonObject.close();//关闭reader流
```
现在fastjson2中,发现已经没有startObject()和endObject()方法了,需要用什么方法来替代?
Contributor guide
Research direction
Start at the fastjson2 JSONReader API and compare it with the fastjson1 call sequence shown in the issue. Confirm the documented replacement for startObject() and endObject() supports streaming over a Reader and preserves key/value iteration; done when the version-appropriate usage and reader-closing behavior are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- backend
- Issue type
- Documentation
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 30/100