使用jackson解析json串得到树模型,然后遍历树模型获得需要的数据
Problem:从网址 http://quotes.money.163.com/hs/service/marketradar_ajax.php?host=http%3A%2F%2Fquotes.money.163.com%2Fhs%2Fservice%2Fmarketradar_ajax.php&page=2&query=STYPE%3AEQA&types=&count=28&type=query&order=desc 获得了如下的json文本:
{"page":2,"count":28,"total":10085,"pagecount":361,"time":"2020-05-03 12:09:45","list":[{"CODE":"0600256","SYMBOL":"600256","NAME":"\u5e7f\u6c47\u80fd\u6e90","PRICE":2.52,"PERCENT":0.028571,"NUMBER":"7,204\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603536","SYMBOL":"603536","NAME":"\u60e0\u53d1\u98df\u54c1","PRICE":13.34,"PERCENT":-0.023426,"NUMBER":"1,876\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0600399","SYMBOL":"600399","NAME":"ST\u629a\u94a2","PRICE":4.21,"PERCENT":-0.029954,"NUMBER":"7,660\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603601","SYMBOL":"603601","NAME":"\u518d\u5347\u79d1\u6280","PRICE":12.16,"PERCENT":-0.055901,"NUMBER":"6,580\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603538","SYMBOL":"603538","NAME":"\u7f8e\u8bfa\u534e","PRICE":34.53,"PERCENT":-0.032502,"NUMBER":"1,803\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5916\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u5356\u5355","TYPE_COLOR":-1},{"CODE":"0601169","SYMBOL":"601169","NAME":"\u5317\u4eac\u94f6\u884c","PRICE":4.98,"PERCENT":0.004032,"NUMBER":"7,031\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0600547","SYMBOL":"600547","NAME":"\u5c71\u4e1c\u9ec4\u91d1","PRICE":36.29,"PERCENT":0.004151,"NUMBER":"5,310\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603012","SYMBOL":"603012","NAME":"\u521b\u529b\u96c6\u56e2","PRICE":7.18,"PERCENT":0.008427,"NUMBER":"6,148\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0600126","SYMBOL":"600126","NAME":"\u676d\u94a2\u80a1\u4efd","PRICE":7.92,"PERCENT":0.077551,"NUMBER":"5,855\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603825","SYMBOL":"603825","NAME":"\u534e\u626c\u8054\u4f17","PRICE":24.91,"PERCENT":0.084458,"NUMBER":"1,044\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603668","SYMBOL":"603668","NAME":"\u5929\u9a6c\u79d1\u6280","PRICE":11.59,"PERCENT":-0.047658,"NUMBER":"4,911\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0601111","SYMBOL":"601111","NAME":"\u4e2d\u56fd\u56fd\u822a","PRICE":7.25,"PERCENT":0.058394,"NUMBER":"7,266\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0600568","SYMBOL":"600568","NAME":"\u4e2d\u73e0\u533b\u7597","PRICE":1.35,"PERCENT":0.007463,"NUMBER":"6,446\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0601975","SYMBOL":"601975","NAME":"\u62db\u5546\u5357\u6cb9","PRICE":2.67,"PERCENT":0.003759,"NUMBER":"13,883\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0688396","SYMBOL":"688396","NAME":"\u534e\u6da6\u5fae","PRICE":37.83,"PERCENT":0.08832,"NUMBER":"3,766\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603533","SYMBOL":"603533","NAME":"\u638c\u9605\u79d1\u6280","PRICE":34,"PERCENT":-0.054242,"NUMBER":"4,391\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0688116","SYMBOL":"688116","NAME":"\u5929\u5948\u79d1\u6280","PRICE":40.01,"PERCENT":0.136648,"NUMBER":"786\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0688166","SYMBOL":"688166","NAME":"\u535a\u745e\u533b\u836f","PRICE":48,"PERCENT":0.046436,"NUMBER":"677\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603815","SYMBOL":"603815","NAME":"\u4ea4\u5efa\u80a1\u4efd","PRICE":21,"PERCENT":0.053688,"NUMBER":"1,947\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0601952","SYMBOL":"601952","NAME":"\u82cf\u57a6\u519c\u53d1","PRICE":10.17,"PERCENT":-0.024928,"NUMBER":"6,356\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0601377","SYMBOL":"601377","NAME":"\u5174\u4e1a\u8bc1\u5238","PRICE":6.03,"PERCENT":0.018581,"NUMBER":"7,780\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0601872","SYMBOL":"601872","NAME":"\u62db\u5546\u8f6e\u8239","PRICE":6.78,"PERCENT":-0.042373,"NUMBER":"15,050\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0601038","SYMBOL":"601038","NAME":"\u4e00\u62d6\u80a1\u4efd","PRICE":7.04,"PERCENT":-0.015385,"NUMBER":"8,200\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0600016","SYMBOL":"600016","NAME":"\u6c11\u751f\u94f6\u884c","PRICE":5.89,"PERCENT":0.003407,"NUMBER":"10,004\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0688015","SYMBOL":"688015","NAME":"\u4ea4\u63a7\u79d1\u6280","PRICE":49.26,"PERCENT":0.05032,"NUMBER":"1,093\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0603719","SYMBOL":"603719","NAME":"\u826f\u54c1\u94fa\u5b50","PRICE":67.38,"PERCENT":-0.005021,"NUMBER":"1,854\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0688222","SYMBOL":"688222","NAME":"\u6210\u90fd\u5148\u5bfc","PRICE":35.01,"PERCENT":0.029101,"NUMBER":"513\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1},{"CODE":"0600556","SYMBOL":"600556","NAME":"\u5929\u4e0b\u79c0","PRICE":16.68,"PERCENT":0.005425,"NUMBER":"4,471\u624b","TITLE":"\u51fa\u73b0\u5927\u4e8e5000\u624b\u6216\u548c\u6d41\u901a\u76d8\u7684\u6bd4\u503c\u5927\u4e8e0.1%\u7684\u5185\u76d8\u6210\u4ea4","TIME":"15:00:05","TYPE":"\u5927\u4e70\u5355","TYPE_COLOR":1}]}
需要从中获得pagecount的文本以及list中每个股票的NAME和CODE。
Solution:使用jackson完成此任务。
Steps:
1.引入jackson依赖
<!-- jackson -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
</dependency> <dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
</dependency>
2.解析
ObjectMapper mapper = new ObjectMapper();
JsonNode node = mapper.readTree(json);// json就是上面的大段待解析文本 pageCount = Integer.parseInt(node.get("pagecount").asText());// 取pagecount JsonNode listNode=node.path("list");
Iterator<JsonNode> iterator = listNode.elements(); // 准备遍历list节点 while (iterator.hasNext()) {
JsonNode stock = iterator.next();
String code=stock.get("CODE").asText(); // 取code
String name=stock.get("NAME").asText(); // 取name Stock s=new Stock(idx++,code,name);
stockList.add(s); //System.out.print(code + " "+name);
}
--2020年5月3日--
参考文档:https://blog.csdn.net/wang_snake/article/details/93719178
使用jackson解析json串得到树模型,然后遍历树模型获得需要的数据的更多相关文章
- SpringMVC Jackson 库解析 json 串属性名大小写自动转换问题
问题描述 在项目开发中,当实体类和表中定义的某个字段为 RMBPrice,首字母是大写的,sql 查询出来的列名也是大写的 RMBPrice,但是使用 jquery 的 ajax 返回请求响应时却出错 ...
- JackSon解析json字符串
JackSon解析json字符串 原文:http://blog.csdn.net/java_huashan/article/details/9353903 概述 jackson解析json例子 准备工 ...
- 记一次FastJSON和Jackson解析json时遇到的中括号问题
版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/24395015 完整版见https://jadyer. ...
- 怎么解析json串在.net中
以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JObject jo = JObject.Parse(json); ...
- 在.net中怎么解析json串 [Error reading JObject from JsonReader. Current JsonReader item is not an obj]
编辑时间:2017-05-10,增加一种转化list的方法 一.以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JO ...
- C++ 解析json串
首先, C++ 解析json串,需要用到第三方库(json_vc71_libmtd.lib).然后,VS2010,创建项目json_read,配置项目属性.最后,拷贝下面的代码就可以看到效果了. #i ...
- 使用 jackson 解析 json 演示样例
首先须要下载3个包,下载地址在Github FasterXML,这三个核心模块各自是: Streaming ("jackson-core") defines low-level s ...
- jackson 解析json问题
1.json串中有key为A,但指定转换的mybean中未定义属性A,会抛异常.处理:mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, fals ...
- Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties
转自:http://blog.csdn.net/ngl272/article/details/70217104 以前解析json用的惯的就是Google的gson了,用惯了基本就用它了,一直也没发现什 ...
随机推荐
- sockjs.js?9be2:1606 GET http://192.168.1.101:8080/sockjs-node/info?t=1583642185049 net::ERR_CONNECTION_TIMED_OUT错误连接方式解决方法
在使用vue-cli脚手架创建项目的时候,在cnpm create app命令后,项目创建成功后通过npm run serve命令运行以后,控制台报错,sockjs.js?9be2:1606 GET ...
- Hexo博客部署到远程仓库(Conding、Gitee、Github)
一.本地环境搭建 1.安装Git Git可以有效.高速的处理各种项目版本管理.也就是用来管理你的hexo博客文章,上传到GitHub的工具. Git下载地址 安装好了之后使用git -version查 ...
- 基于Asp.net Core 3.1实现的Redis及MemoryCache缓存助手CacheHelper
这几天在面试,这个关于Redis缓存的博客一直没空写,今天总算有点时间了. 从很久很久之前,我就一直想学Redis了,反正看到各大招聘网上都要求Redis,不学就太落后了. 一开始我是按微软官网文档那 ...
- 微信小程序 progress 进度条 内部圆角及内部条渐变色
微信小程序progress进度条内部圆角及渐变色 <view class="progress-box"> <progress percent="80&q ...
- vue的使用规范之v-if 与 v-for 一起使用
当 v-if 与 v-for 一起使用时,v-for 具有比 v-if 更高的优先级,这意味着 v-if 将分别重复运行于每个 v-for 循环中 所以,不推荐v-if和v-for同时使用 使用推荐方 ...
- vue-cli 安装教程(转)
vue-cli这个构建工具大大降低了webpack的使用难度,支持热更新,有webpack-dev-server的支持,相当于启动了一个请求服务器,给你搭建了一个测试环境,只关注开发就OK. 1.安装 ...
- Golang Gtk+3教程:开始
GTK+是一个控件工具包.每个通过GTK+创建的用户界面由一些控件组成. 控件是层级式的,window控件是主容器,通过在window中添加按钮.下拉菜单.输入字段等其他控件构成用户界面. 如果是复杂 ...
- 使用 .NET Core 3.x 构建RESTful Api(第三部分)
关于HTTP HEAD 和 HTTP GET: 从执行性能来说,这两种其实并没有什么区别.最大的不同就是对于HTTP HEAD 来说,Api消费者请求接口数据时,如果是通过HTTP HEAD的方式去请 ...
- ganglia访问时出现"You don't have permission to access /ganglia/ on this server"
安装ganglia后,访问浏览器出现"You don't have permission to access /ganglia/ on this server" 按照网络上的要求配 ...
- Spark中遇到的问题
spark启动slave时提示 JAVA_HOME is not set 解决方法: 在sbin目录spark-config.sh 中添加自己的jdk 路径export JAVA_HOME=/home ...