原文http://blog.csdn.net/gebitan505/article/details/17005735

custom.json:

{
    "country":"USA",   
    "countryInfo":{"golden":40,"silver":23,"copper":33,"tank":1},  
"countryDetail":[  
    {"id":"no","header":"号码","fieldIndex":"no","sortOrder":null,"printable":true},  
    {"id":"name","header":"姓名","fieldIndex":"name","sortOrder":null,"printable":true},  
    {"id":"total","header":"总成绩","fieldIndex":"total","sortOrder":null,"printable":true},  
    {"id":"detail","header":"详细信息","fieldIndex":"detail","sortOrder":null,"printable":true}  
   ], 

"orgood":true}

Java的Bean及解析:

import java.io.File;
import java.io.IOException;
import com.fasterxml.jackson.core.JsonParseException;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;

public class Bean{
    
    private String country;
    private boolean orgood;
    private Country countryInfo;
    private CountryDetail[] countryDetail;
    
    public String getCountry() {
        return country;
    }

public void setCountry(String country) {
        this.country = country;
    }

public boolean isOrgood() {
        return orgood;
    }

public void setOrgood(boolean orgood) {
        this.orgood = orgood;
    }

public Country getCountryInfo() {
        return countryInfo;
    }

public void setCountryInfo(Country countryInfo) {
        this.countryInfo = countryInfo;
    }

public CountryDetail[] getCountryDetail() {
        return countryDetail;
    }

public void setCountryDetail(CountryDetail[] countryDetail) {
        this.countryDetail = countryDetail;
    }
    
    public static class Country{
        public String getGolden() {
            return golden;
        }
        public void setGolden(String golden) {
            this.golden = golden;
        }
        public String getSilver() {
            return silver;
        }
        public void setSilver(String silver) {
            this.silver = silver;
        }
        public String getCopper() {
            return copper;
        }
        public void setCopper(String copper) {
            this.copper = copper;
        }
        public String getTank() {
            return tank;
        }
        public void setTank(String tank) {
            this.tank = tank;
        }
        private String golden;
        private String silver;
        private String copper;
        private String tank;
        
    }
    
    public static class CountryDetail{
        public String getId() {
            return id;
        }
        public void setId(String id) {
            this.id = id;
        }
        public String getHeader() {
            return header;
        }
        public void setHeader(String header) {
            this.header = header;
        }
        public String getFieldIndex() {
            return fieldIndex;
        }
        public void setFieldIndex(String fieldIndex) {
            this.fieldIndex = fieldIndex;
        }
        public String getSortOrder() {
            return sortOrder;
        }
        public void setSortOrder(String sortOrder) {
            this.sortOrder = sortOrder;
        }
        public boolean isPrintable() {
            return printable;
        }
        public void setPrintable(boolean printable) {
            this.printable = printable;
        }
        private String id;
        private String header;
        private String fieldIndex;
        private String sortOrder;
        private boolean printable;
        
    }
    
    public static void main(String args[]){
        ObjectMapper mapper = new ObjectMapper();
        try {
            Bean bean = mapper.readValue(new File("custom.json"), Bean.class);

//读取

System.out.println("Country:"+bean.getCountry());
            System.out.println("CountryInfo:"+bean.getCountryInfo().getGolden());
            System.out.println("CountryDetail:"+bean.getCountryDetail()[1].getHeader());
            System.out.println("orgood:"+bean.isOrgood());
        } catch (JsonParseException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (JsonMappingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

使用Jackson解析Json示例的更多相关文章

  1. JackSon解析json字符串

    JackSon解析json字符串 原文:http://blog.csdn.net/java_huashan/article/details/9353903 概述 jackson解析json例子 准备工 ...

  2. 记一次FastJSON和Jackson解析json时遇到的中括号问题

    版权声明:本文为博主原创文章,未经博主同意不得转载. https://blog.csdn.net/jadyer/article/details/24395015 完整版见https://jadyer. ...

  3. 使用 jackson 解析 json 演示样例

    首先须要下载3个包,下载地址在Github FasterXML,这三个核心模块各自是: Streaming ("jackson-core") defines low-level s ...

  4. Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties

    转自:http://blog.csdn.net/ngl272/article/details/70217104 以前解析json用的惯的就是Google的gson了,用惯了基本就用它了,一直也没发现什 ...

  5. [转]Jackson 解析json数据之忽略解析字段注解@JsonIgnoreProperties

    以前解析json用的惯的就是Google的gson了,用惯了基本就用它了,一直也没发现什么大问题,因为都是解析简单的json数据.但是最近学习springboot,要解析一个比较复杂的json数据.就 ...

  6. Jackson 解析 JSON 详细教程

    点赞再看,动力无限. 微信搜「程序猿阿朗 」. 本文 Github.com/niumoo/JavaNotes 和 未读代码博客 已经收录,有很多知识点和系列文章. JSON 对于开发者并不陌生,如今的 ...

  7. 使用jackson解析JSON数据

    本文介绍使用jackson来对json数据进行解析操作 首先,需要去官网下载jackson,本文使用的是(jackson-all-1.9.11.jar) 主要通过ObjectMapper对json进行 ...

  8. 使用jackson解析json串得到树模型,然后遍历树模型获得需要的数据

    Problem:从网址 http://quotes.money.163.com/hs/service/marketradar_ajax.php?host=http%3A%2F%2Fquotes.mon ...

  9. jackson 解析json问题

    1.json串中有key为A,但指定转换的mybean中未定义属性A,会抛异常.处理:mapper.configure(Feature.FAIL_ON_UNKNOWN_PROPERTIES, fals ...

随机推荐

  1. jQuery获取Select选中的Text和Value

    获取Select选中的Text和Value语法解释:$("#select_id").change(function(){//code...});   // 为Select添加事件, ...

  2. java程序员保持天天快乐的6个习惯

    忍不住感叹,我第一次对Buffer(在社交媒体上发布最简单的方式)有所想法已经差不多是两年前的事了.并且,在我有想法的一年半前,我还在前面那家新创公司工作的时...... 忍不住感叹,我第一次对Buf ...

  3. input框中的name和id的区别

    1. 可以说几乎每个做过Web开发的人都问过,到底元素的ID和Name有什么区别阿?为什么有了ID还要有Name呢?! 而同样我们也可以得到最classical的答案:ID就像是一个人的身份证号码,而 ...

  4. 用Kotlin改写PHP程序是什么样的体验

    学Kotlin其实要看:http://kotlinlang.org/docs/kotlin-docs.pdf 在线版是不完整的!!!少了一些章节,会有点难看懂后面的文档. 我选择了WordPress里 ...

  5. No.022:Generate Parentheses

    问题: Given n pairs of parentheses, write a function to generate all combinations of well-formed paren ...

  6. 如何在MFC界面开发中响应Button按钮的Down和Up事件

    通过尝试有两种方案可以解决这个问题,第一种方案是通过PreTranslateMessage函数在调度消息之前对消息类型进行筛选,第二种方案是重载CButton类,在重载后的类CForTestButto ...

  7. 常见.NET功能代码汇总 (2)

    常见.NET功能代码汇总 23,获取和设置分级缓存 获取缓存:首先从本地缓存获取,如果没有,再去读取分布式缓存写缓存:同时写本地缓存和分布式缓存 private static T GetGradeCa ...

  8. MFC--响应鼠标和键盘操作

    一个程序最重要的部分之一是对鼠标和键盘操作的响应. 一.  理解鼠标事件.之前对鼠标事件的认识仅仅局限于处理控件的单击与双击事件.但实际鼠标的操作包含很多.这里将以一个画图的小程序讲解对鼠标的响应. ...

  9. [转]实现文字跑马灯效果,scrolling text from right to left

    <div> <marquee direction="left" behavior="scroll" scrollamount="10 ...

  10. android:Intent匹配action,category和data原则

    1.当你在androidmanifest里面定义了一个或多个action时 你使用隐式意图其他activity或者service时,规定你隐式里面的action必须匹配XML中定义的action,可以 ...