<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency> <dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.5</version>
</dependency>
    public static void jsonTree(JsonElement e)
{
if (e.isJsonNull())
{
System.out.println(e.toString());
return;
} if (e.isJsonPrimitive())
{
System.out.println(e.toString());
return;
} if (e.isJsonArray())
{
JsonArray ja = e.getAsJsonArray();
if (null != ja)
{
for (JsonElement ae : ja)
{
jsonTree(ae);
}
}
return;
} if (e.isJsonObject())
{
Set<Entry<String, JsonElement>> es = e.getAsJsonObject().entrySet();
for (Entry<String, JsonElement> en : es)
{
jsonTree(en.getValue());
}
}
} public static void main(String[] args)
{
try
{
String json = FileUtils.readFileToString(new File("C://test//test.txt"), "UTF-8");
JsonParser p = new JsonParser();
JsonElement e = p.parse(json);
jsonTree(e);
}
catch(Exception e)
{
e.printStackTrace();
}
}

Java用Gson遍历json所有节点的更多相关文章

  1. Java用Jackson遍历json所有节点

    <!-- jackson begin --> <dependency> <groupId>com.fasterxml.jackson.core</groupI ...

  2. java 扁平化输出json所有节点key/value

    本章主要介绍用java实现扁平化输出json所有节点key/value(包含所有内层子节点) 1.json结构 目的输出bill_list下的datalist里的子节点key/value 2.实现代码 ...

  3. JAVA使用Gson解析json数据,实例

    封装类Attribute: public class Attribute { private int id; private String name; private int age; public ...

  4. Java 使用gson 解析 Json

    json数据 { "resultcode": "200", "reason": "successed!", " ...

  5. Java 利用Gson将json字符串转换为List<Map<String, String>>

    json字符串类似于: [ { "userPhone": "123", "userNo": "123-2", " ...

  6. Gson把json串转换成java实体对象

    Gson把json串转换成java实体对象的方法如下: 1.首先导入Gson的jar包,网上可以下载. java实体对象如下: public class Model { private double ...

  7. 前端笔记之jQuery(下)事件&节点操作&净位置&拖拽&页面卷动值&遍历JSON

    一.监听事件大全 1.1 JavaScript事件 onblur 元素失去焦点 onchange 用户改变域的内容 onclick 鼠标点击某个对象 ondblclick 鼠标双击某个对象 onfoc ...

  8. 遍历 JSON JavaScript 对象树中的所有节点

    我想要遍历 JSON 对象树中,但为何找不到任何一间图书馆.这似乎是不难,但感觉就像重新发明轮子. 在 XML 中有很多教程演示如何遍历 XML DOM 树:( 解决方法 1: 如果你认为 jQuer ...

  9. <摘录>Gson对Java嵌套对象和JSON字符串之间的转换

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,具有良好的跨平台特性.近几年来已经和XML一样成为C/S架构中广泛采用的数据格式.有关JSON的更多知识, ...

随机推荐

  1. vue中根据当前时间进行排序

    computed: { newdataList: function() { return this.sortKey(this.dataList, "addtime"); } }, ...

  2. js中的offsetLeft和style.left

    (1)style.left是带单位"px"的,而offsetLeft没有单位,另外,style.left必须是内联样式,或者在JS中通过style.left赋值,否则取得的将为空字 ...

  3. (转)Thread中yield方法

    先上一段代码 public class YieldExcemple { public static void main(String[] args) { Thread threada = new Th ...

  4. MySQL 基础 简单操作

    一.数据库基础 什么是数据库 数据库:保存有组织的数据的容器(通常是一个文件或一组文件). 表:是一种结构化的文件,可以用来存储数据(类似Excel表).数据库就是由成千上万个表组成. 什么事SQL ...

  5. 【LeetCode每天一题】Add Two Numbers(两链表相加)

    You are given two non-empty linked lists representing two non-negative integers. The digits are stor ...

  6. GIt 修改上一次的提交(保持Change-Id不变即可)

    背景: 代码提交到gerrit以后,发现提交不对或者缺少了某个文件的改动. 解决: 比如发现test.txt 文件忘记修改了 step1. vim test.txt 修改 step2. git add ...

  7. 如何设置locale

    什么是 locale? 是根据计算机用户所使用的语言,所在国家或者地区,以及当地的文化传统所定义的一个软件运行时的语言环境 locale定义文件放在目录 /usr/share/i18n/locales ...

  8. securecrt配置经验总结(home.key和颜色)

    还是用securecrt portable方便,配好了,换个机器,打包拷贝过去就行了.不用从两个地方去打包. 参考了网上的资料,颜色参考http://www.jackxiang.com/post/58 ...

  9. iOS Xcode 用 GitHub 托管项目

    直接在xcode里用Github教程:http://jingyan.baidu.com/article/ab0b5630936ab6c15afa7d1c.html 经过本人尝试之后,发现,使用官网的客 ...

  10. 查看手机cpu信息

    adb shell getprop ro.product.cpu.abi