利用fastjson解析大文本JSON
来源:互联网 发布:java 解压缩tar.gz 编辑:程序博客网 时间:2024/04/27 07:17
public static void readBigJson(){ String json = "{" + "\"array\": [1,2,3]," + "\"arraylist\": [" + "{\"a\": \"b\"," + "\"c\": \"d\"," + "\"e\": \"f\"}," + "{\"a\": \"b\"," + "\"c\": \"d\"," + "\"e\": \"f\"}," + "{\"a\": \"b\"," + "\"c\": \"d\"," + "\"e\": \"f\"} " + "]," + "\"object\": {" + "\"a\": \"b\"," + "\"c\": \"d\"," + "\"e\": \"f\"}," + "\"string\": \"Hello World\"" + "}"; // 如果json数据以形式保存在文件中,用FileReader进行流读取,path为json数据文件路径。 // JSONReader reader = new JSONReader(new FileReader(path)); // 为了直观,方便运行,就用StringReader做示例! JSONReader reader = new JSONReader(new StringReader(json)); reader.startObject(); System.out.print("start read json with fastjson"); while (reader.hasNext()) { String key = reader.readString(); System.out.println("key " + key); if (key.equals("array")) { reader.startArray(); System.out.println("start " + key); while (reader.hasNext()) { String item = reader.readString(); System.out.println(item); } reader.endArray(); System.out.println("end " + key); } else if (key.equals("arraylist")) { reader.startArray(); System.out.println("start " + key); while (reader.hasNext()) { reader.startObject(); System.out.println("start arraylist item"); while (reader.hasNext()) { String arrayListItemKey = reader.readString(); String arrayListItemValue = reader.readObject().toString(); System.out.print("key " + arrayListItemKey); System.out.println(":value " + arrayListItemValue); } reader.endObject(); System.out.println("end arraylist item"); } reader.endArray(); System.out.println("end " + key); } else if (key.equals("object")) { reader.startObject(); System.out.println("start object item"); while (reader.hasNext()) { String objectKey = reader.readString(); String objectValue = reader.readObject().toString(); System.out.print("key " + objectKey); System.out.println(":value " + objectValue); } reader.endObject(); System.out.println("end object item"); } else if (key.equals("string")) { System.out.println("start string"); String value = reader.readObject().toString(); System.out.println("value " + value); System.out.println("end string"); } } reader.endObject(); System.out.println("start fastjson");}
阅读全文
0 0
- 利用fastjson解析大文本JSON
- Android 利用fastjson进行json解析
- Android 利用fastjson进行json解析
- 利用fastjson解析即信语音json
- Json解析,FastJson解析
- 性能优化之解析:fastJson快速解析大数据json
- 利用 fastjson.jar 把对象解析成Json 数据
- Android studio利用GsonFormat和fastjson快速解析JSON!
- JSON 之FastJson解析
- Android FastJson,json解析
- JSON 之FastJson解析
- JSON 之FastJson解析
- Json解析之FastJson
- JSON 之FastJson解析
- JSON 之FastJson解析
- JSON 之FastJson解析
- JSON 之FastJson解析
- JSON 之FastJson解析
- [日推荐]『八大洲旅游预订』十一,来一次说走就走的奢华跨国旅
- DES加解密操作
- 十六、shell文件包含、引用
- 函数指针:阅读顺序与C++11一些新特性使用
- 正则表达式
- 利用fastjson解析大文本JSON
- freemarker导出Word文档并在其中插入图片
- 《android开发艺术探索笔记》Part 4、View的工作原理
- C++单件模式:可继承的模板类
- maven 打包.bat文件和安装jar到仓库
- 笔记
- 小程序学习的第一天
- Android studio 上传到 GitHub
- Python文件操作