递归解析任意层的json
package com.sun.test;
import java.util.Iterator;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
/**
*
* @company
* @author superboo
* @version 3.0
* @date 2014-5-21 上午09:45:51
*/
public class HelloWorld {
public String getJsonStr1() {
String jsonStr = "{"
+ "\"list\": ["
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463881.shtml\","
+ "\"title\": \"秦皇岛市城市管理局数字城管GPS车辆管理系统公开采购\","
+ "\"time\": \"2014-05-20 18:58:50\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463904.shtml\","
+ "\"title\": \"宁晋县公安局贾家口派出所工程\","
+ "\"time\": \"2014-05-20 18:52:10\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463903.shtml\","
+ "\"title\": \"宁晋县公安局耿庄桥派出所工程\","
+ "\"time\": \"2014-05-20 18:49:30\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463838.shtml\","
+ "\"title\": \"河北医科大学食堂油改气项目公开招标公告\","
+ "\"time\": \"2014-05-20 18:03:48\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463601.shtml\","
+ "\"title\": \"青龙满族自治县教育局2014年中小学校舍安全工程公开招标公告\","
+ "\"time\": \"2014-05-20 17:06:12\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463590.shtml\","
+ "\"title\": \"清东陵孝陵主神道一孔、五孔、七孔石桥修缮工程监理公开招标公告\","
+ "\"time\": \"2014-05-20 17:03:24\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463668.shtml\","
+ "\"title\": \"晋州市教育局中小学计算机采购项目公开招标公告\","
+ "\"time\": \"2014-05-20 16:58:58\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463666.shtml\","
+ "\"title\": \"固安县畜牧兽医局检测设备采购公开招标公告\","
+ "\"time\": \"2014-05-20 16:57:07\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463446.shtml\","
+ "\"title\": \"宁晋县2014年高标准基本农田建设项目勘查设计公开招标公告\","
+ "\"time\": \"2014-05-20 16:44:24\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463210.shtml\","
+ "\"title\": \"内丘县教育局幼儿园玩教具采购项目公开招标公告\","
+ "\"time\": \"2014-05-20 16:30:42\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463186.shtml\","
+ "\"title\": \"黄骅市2014年农桥重建工程(第一批)公开招标公告\","
+ "\"time\": \"2014-05-20 16:27:35\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463134.shtml\","
+ "\"title\": \"柏乡县2014年农业综合开发高标准农田建设项目公开招标公告\","
+ "\"time\": \"2014-05-20 16:22:06\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463048.shtml\","
+ "\"title\": \"石家庄市第一中学东校区校园数字广播系统改造工程预中标公告\","
+ "\"time\": \"2014-05-20 16:13:10\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462957.shtml\","
+ "\"title\": \"唐山市园林绿化管理局唐山植物园建成区景观提升工程一标段河北省政府采购公开招标公告\","
+ "\"time\": \"2014-05-20 15:42:20\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462954.shtml\","
+ "\"title\": \"唐山市园林绿化管理局唐山植物园建成区景观提升工程一标段监理河北省政府采购公开招标公告\","
+ "\"time\": \"2014-05-20 15:40:55\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462951.shtml\","
+ "\"title\": \"唐山市园林绿化管理局唐山市城市道路景观提升绿化工程设计河北省政府采购公开招标公告\","
+ "\"time\": \"2014-05-20 15:39:35\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462600.shtml\","
+ "\"title\": \"唐山市第二医院采购悬吊式数字放射成像系统公开招标公告\","
+ "\"time\": \"2014-05-20 14:48:55\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462528.shtml\","
+ "\"title\": \"石家庄市体育运动学校体育器材采购项目公开招标公告\","
+ "\"time\": \"2014-05-20 14:33:12\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462243.shtml\","
+ "\"title\": \"河北宏信招标有限公司河北师范大学生物制造中试平台设备采购(二次)公开招标公告\","
+ "\"time\": \"2014-05-20 12:03:08\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462156.shtml\","
+ "\"title\": \"河北化工医药职业技术学院电机与电气控制及物化实验仪器设备采购公开招标公告\","
+ "\"time\": \"2014-05-20 11:19:41\"" + "}" + "],"
+ "\"page\": \"总18163篇 共909页 \"" + "}";
return jsonStr;
}
public String getJsonStr2() {
String jsonStr = "{"
+ "\"list\": ["
+ "{"
+ "\"url\": \"http://www.ceshi.gov.cn\","
+ "\"title\": \"这是一个我测试加入的东西\","
+ "\"time\": \"2014-05-21 18:58:50\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463881.shtml\","
+ "\"title\": \"秦皇岛市城市管理局数字城管GPS车辆管理系统公开采购\","
+ "\"time\": \"2014-05-20 18:58:50\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463904.shtml\","
+ "\"title\": \"宁晋县公安局贾家口派出所工程\","
+ "\"time\": \"2014-05-20 18:52:10\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463903.shtml\","
+ "\"title\": \"宁晋县公安局耿庄桥派出所工程\","
+ "\"time\": \"2014-05-20 18:49:30\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463838.shtml\","
+ "\"title\": \"河北医科大学食堂油改气项目公开招标公告\","
+ "\"time\": \"2014-05-20 18:03:48\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463601.shtml\","
+ "\"title\": \"青龙满族自治县教育局2014年中小学校舍安全工程公开招标公告\","
+ "\"time\": \"2014-05-20 17:06:12\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463590.shtml\","
+ "\"title\": \"清东陵孝陵主神道一孔、五孔、七孔石桥修缮工程监理公开招标公告\","
+ "\"time\": \"2014-05-20 17:03:24\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463668.shtml\","
+ "\"title\": \"晋州市教育局中小学计算机采购项目公开招标公告\","
+ "\"time\": \"2014-05-20 16:58:58\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463666.shtml\","
+ "\"title\": \"固安县畜牧兽医局检测设备采购公开招标公告\","
+ "\"time\": \"2014-05-20 16:57:07\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463446.shtml\","
+ "\"title\": \"宁晋县2014年高标准基本农田建设项目勘查设计公开招标公告\","
+ "\"time\": \"2014-05-20 16:44:24\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463210.shtml\","
+ "\"title\": \"内丘县教育局幼儿园玩教具采购项目公开招标公告\","
+ "\"time\": \"2014-05-20 16:30:42\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463186.shtml\","
+ "\"title\": \"黄骅市2014年农桥重建工程(第一批)公开招标公告\","
+ "\"time\": \"2014-05-20 16:27:35\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463134.shtml\","
+ "\"title\": \"柏乡县2014年农业综合开发高标准农田建设项目公开招标公告\","
+ "\"time\": \"2014-05-20 16:22:06\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3463048.shtml\","
+ "\"title\": \"石家庄市第一中学东校区校园数字广播系统改造工程预中标公告\","
+ "\"time\": \"2014-05-20 16:13:10\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462957.shtml\","
+ "\"title\": \"唐山市园林绿化管理局唐山植物园建成区景观提升工程一标段河北省政府采购公开招标公告\","
+ "\"time\": \"2014-05-20 15:42:20\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462954.shtml\","
+ "\"title\": \"唐山市园林绿化管理局唐山植物园建成区景观提升工程一标段监理河北省政府采购公开招标公告\","
+ "\"time\": \"2014-05-20 15:40:55\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462951.shtml\","
+ "\"title\": \"唐山市园林绿化管理局唐山市城市道路景观提升绿化工程设计河北省政府采购公开招标公告\","
+ "\"time\": \"2014-05-20 15:39:35\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462600.shtml\","
+ "\"title\": \"唐山市第二医院采购悬吊式数字放射成像系统公开招标公告\","
+ "\"time\": \"2014-05-20 14:48:55\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462528.shtml\","
+ "\"title\": \"石家庄市体育运动学校体育器材采购项目公开招标公告\","
+ "\"time\": \"2014-05-20 14:33:12\""
+ "},"
+ "{"
+ "\"url\": \"http://www.ccgp.gov.cn/cggg/dfbx/gkzb/201405/t20140520_3462243.shtml\","
+ "\"title\": \"河北宏信招标有限公司河北师范大学生物制造中试平台设备采购(二次)公开招标公告\","
+ "\"time\": \"2014-05-20 12:03:08\"" + "}],"
+ "\"page\": \"总18164篇 共909页 \"" + "}";
return jsonStr;
}
public String getJsonStr3() {
String jsonStr = "{'ret': 0,'msg': 'success','act': 3004,'data':[{'sid':1,'content':'11正文','pics':[{'url':'http://xxxxxx'}],'videoPic':'','videoUrl':'','timeStamp': 111111111111,'custId':'1234','custName':'test','custImg':'','likeCount':0,'commentCount':0,'giftsCount':0,'likes':[],'gifts':[],'comments':[]},{'sid':1,'content':'22正文','pics':[{o1:'0_1'},{o2:'0—2'}],'videoPic':'','videoUrl':'','timeStamp': 111111111111,'custId':'1234','custName':'test','custImg':'','likeCount':0,'commentCount':0,'giftsCount':0,'likes':[],'gifts':[],'comments':[]}]}";
return jsonStr;
}
@SuppressWarnings("rawtypes")
public void analysisJson(Object objJson){
//如果obj为json数组
if(objJson instanceof JSONArray){
JSONArray objArray = (JSONArray)objJson;
for (int i = 0; i < objArray.size(); i++) {
analysisJson(objArray.get(i));
}
}
//如果为json对象
else if(objJson instanceof JSONObject){
JSONObject jsonObject = (JSONObject)objJson;
Iterator it = jsonObject.keys();
while(it.hasNext()){
String key = it.next().toString();
Object object = jsonObject.get(key);
//如果得到的是数组
if(object instanceof JSONArray){
JSONArray objArray = (JSONArray)object;
analysisJson(objArray);
}
//如果key中是一个json对象
else if(object instanceof JSONObject){
analysisJson((JSONObject)object);
}
//如果key中是其他
else{
System.out.println("["+key+"]:"+object.toString()+" ");
}
}
}
}
public static void main(String[] args) {
HelloWorld hw = new HelloWorld();
JSONObject jsonObject = JSONObject.fromObject(hw.getJsonStr3());
hw.analysisJson(jsonObject);
}
}
递归解析任意层的json的更多相关文章
- fastjson解析任意json
fastjson解析任意json到bean 解析案例的代码 package com.base.config; import java.util.List; import com.alibaba.fas ...
- Android 解析未知格式的json数据
1.递归一有的时候我们需要解析未知的json.或者说是动态的json.那么我们并不知道key具体是多少,或者说key不是固定的.这时候就需要解析动态key的方法. 这个方法是我在实现解析前台传入的js ...
- python中jsonpath模块,解析多层嵌套的json数据
1. jsonpath介绍用来解析多层嵌套的json数据;JsonPath 是一种信息抽取类库,是从JSON文档中抽取指定信息的工具,提供多种语言实现版本,包括:Javascript, Python, ...
- DNS(一)之禁用权威域名服务器递归解析
DNS dns是互联网中最核心的带层级的分布式系统,负责把域名解析成ip,把IP解析出域名,以及宣告邮件路由信息等等,使得使用域名访问网站,收发邮件成了可能. bind(berkeley Intern ...
- iOS开发——数据解析Swift篇&简单json数据处理
简单json数据处理 //loadWeather var url = NSURL(string: "http://www.weather.com.cn/adat/sk/101240701.h ...
- 吴恩达深度学习第1课第4周-任意层人工神经网络(Artificial Neural Network,即ANN)(向量化)手写推导过程(我觉得已经很详细了)
学习了吴恩达老师深度学习工程师第一门课,受益匪浅,尤其是吴老师所用的符号系统,准确且易区分. 遵循吴老师的符号系统,我对任意层神经网络模型进行了详细的推导,形成笔记. 有人说推导任意层MLP很容易,我 ...
- scrapy递归解析和post请求
递归解析 递归爬取解析多页页面数据 每一个页面对应一个url,则scrapy工程需要对每一个页码对应的url依次发起请求,然后通过对应的解析方法进行作者和段子内容的解析. 实现方案: 1.将每一个页码 ...
- JSON的简单使用_解析前台传来的JSON数据
package cn.rocker.json; import org.junit.Test; import net.sf.json.JSONArray; import net.sf.json.JSON ...
- 使用GSON和泛型解析约定格式的JSON串(转)
时间紧张,先记一笔,后续优化与完善. 解决的问题: 使用GSON和泛型解析约定格式的JSON串. 背景介绍: 1.使用GSON来进行JSON串与java代码的互相转换. 2.JSON的格式如下三种: ...
随机推荐
- php curl拉取远程图片
<?php $url = "图片绝对地址/thumbnail.jpg"; $filename = 'curl.jpg'; getImg($url, $filename); / ...
- Maven中央(或国内)仓库地址
maven官方 http://repo1.maven.org/maven2/ 或 http://repo2.maven.org/maven2/ (延迟低一些) osc 本家 http://maven ...
- linux和windows双系统时间错误解决方法
转自http://www.2cto.com/os/201204/126212.html windows时间会慢8小时,原因: 两个概念: UTC即Universal Time Coordinated, ...
- PNPOLY - Point Inclusion in Polygon Test
https://www.ecse.rpi.edu/Homepages/wrf/Research/Short_Notes/pnpoly.html The C Code Here is the code, ...
- vim 替换
摘自: vim替换命令 替換(substitute) :[range]s/pattern/string/[c,e,g,i] range 指的是範圍,1,7 指從第一行至第七行,1,$ 指從第一行至最後 ...
- ORACLE 11g dblink 配置升级
1.如果需要创建全局 DBLink,则需要先确定用户有创建 dblink 的权限: select * from user_sys_privs where privilege like upper('% ...
- 使用Cookie来统计浏览次数,当天重复刷新不增加
这是一种不严谨的做法,在浏览量不是很重要的时候可以使用 var oldCookie = Request.Cookies["newsCookie"]; if (oldCookie = ...
- .Net Core 中使用Session
1.在 Startup 中 ConfigureServices 添加Session public void ConfigureServices(IServiceCollection services) ...
- VS中调试时监控线程的最后错误代码
进行调试的时候,监控线程的最后错误代码是非常有用的. 在 Microsoft Visual studio 中,Microsoft 的调试程序支持一个非常有用的特性,即可以配置 Watch 窗口,以便始 ...
- webpy 开发环境搭建问题之Mysql-python安装
关于python核心编程已经看了差不多,准备搞些框架方面的学习,本来想打算看看Django的,但是朋友推荐先看看轻量级的flask或者webpy的开发,所以晚上回来,搭建下开发环境(PS:搭建过程中由 ...