java解析json

java解析json
 1 /*
 2      * 解析Json得到数组信息
 3      */
 4     public BrandData analyzeJson(String json){
 5         if(json==null){
 6             return null;
 7         }
 8         try {
 9             JsonMapper mapper = JsonMapper.nonDefaultMapper();
10             return mapper.fromJson(json, BrandData[].class)[0];
11         } catch (Exception e) {
12             //注:因原数据库中存储记录非json形式,对于异常json采用截取字符串形式
13             BrandData brandData = new BrandData();
14             String[] strs = json.split("\"");
15             brandData.setMake(strs[7]);
16             brandData.setModel(strs[3]);
17             return brandData;
18         }
19     }
20 
21 
22 
23 
24 
25 
26 /**
27  * 解析tab_sLegalize的json格式Brands
28  * 
29  * @author xzm
30  *
31  */
32 public class BrandData {
33 
34     private String model;
35     private String make;
36     private List<String> series;
37 
38     public String getModel() {
39         return model;
40     }
41 
42     public void setModel(String model) {
43         this.model = model;
44     }
45 
46     public String getMake() {
47         return make;
48     }
49 
50     public void setMake(String make) {
51         this.make = make;
52     }
53 
54     public List<String> getSeries() {
55         return series;
56     }
57 
58     public void setSeries(List<String> series) {
59         this.series = series;
60     }
61 }
java解析json

 

1
2
3
4
5
6
7
8
解析用到的jar
<br>
<br>用到的jar包:jackson-annotations-2.1.5.jar
jackson-core-2.1.5.jar
jackson-databind-2.1.5.jar
jackson-module-jaxb-annotations-2.1.5.jar
 
日志的相关配置:
java解析json
 1 logback日志的配置:
 2 logback-core-1.0.13.jar
 3 
 4 
 5 <?xml version="1.0" encoding="UTF-8"?>
 6 <configuration>
 7     <appender name="console" class="ch.qos.logback.core.ConsoleAppender">
 8         <encoder>
 9             <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
10         </encoder>
11     </appender>
12 
13     <appender name="rollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
14         <file>logs/logbackLog.log</file>
15         <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
16             <fileNamePattern>logs/carmall-mall.%d{yyyy-MM-dd}.log</fileNamePattern>
17         </rollingPolicy>
18         <encoder>
19             <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
20         </encoder>
21     </appender>
22 
23     <!-- project default level -->
24     <logger name="cn.iautos.carmall" level="INFO" />
25 
26     <!--log4jdbc -->
27     <logger name="jdbc.sqltiming" level="INFO"/>
28 
29     <root level="info">
30         <appender-ref ref="console" />
31         <appender-ref ref="rollingFile" />
32     </root>
33 </configuration>
java解析json

相关代码:

java解析json

上一篇:C#学习笔记一:委托、匿名函数、Lambda 表达式


下一篇:IOS 学习:UITableView 使用详解1