我有一个json字符串,我应该deSerialize到下面的类
class Data <T> {
int found;
Class<T> hits
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做?这是通常的方式
mapper.readValue(jsonString, Data.class);
Run Code Online (Sandbox Code Playgroud)
但我如何提及T代表什么?
JSON字符串如下
{
"rank":"-text_relevance",
"match-expr":"(label 'star wars')",
"hits":{
"found":7,
"start":0,
"hit":[
{"id":"tt1185834",
"data":{
"actor":["Abercrombie, Ian","Baker, Dee","Burton, Corey"],
"title":["Star Wars: The Clone Wars"]
}
},
.
.
.
{"id":"tt0121766",
"data":{
"actor":["Bai, Ling","Bryant, Gene","Castle-Hughes, Keisha"],
"title":["Star Wars: Episode III - Revenge of the Sith"]
}
}
]
},
"info":{
"rid":"b7c167f6c2da6d93531b9a7b314ad030b3a74803b4b7797edb905ba5a6a08",
"time-ms":2,
"cpu-time-ms":0
}
}
Run Code Online (Sandbox Code Playgroud)
它有很多字段,但我只想要数据字段.这不起作用:
mapper.readvalue(jsonString,Data.class);
Run Code Online (Sandbox Code Playgroud)
如何让杰克逊只阅读"数据"字段?
我错误地发布了这个问题.我在这里正确地发布了这个问题......
我得到一个json字符串作为HTTP响应.我知道它的结构.它如下:
public class Json<T> {
public Hits<T> hits;
}
public class Hits<T> {
public int found;
public int start;
public ArrayList<Hit<T>> hit;
}
public class Hit<T> {
public String id;
public Class<T> data;
}
Run Code Online (Sandbox Code Playgroud)
"数据"字段可以属于任何类.我只会在运行时知道它.我会把它作为一个参数.这就是我反序列化的方式.
public <T> void deSerialize(Class<T> clazz) {
ObjectMapper mapper = new ObjectMapper();
mapper.readValue(jsonString, new TypeReference<Json<T>>() {});
}
Run Code Online (Sandbox Code Playgroud)
但是我收到了一个错误 -
无法从java.lang.class访问私有java.lang.class.Class().无法设置访问权限.无法使java.lang.Class构造函数可访问
我无法在Ubuntu上的R 3.0.2中安装ggplot2.
我跑的时候
install.packages('ggplot2',dependencies = TRUE)
Run Code Online (Sandbox Code Playgroud)
我收到以下错误.
> install.packages('ggplot2',dependencies = TRUE)
Installing package into ‘/home/gowthamn/R/x86_64-pc-linux-gnu-library/3.0’
(as ‘lib’ is unspecified)
Warning in install.packages :
dependencies ‘plyr’, ‘testthat’ are not available
also installing the dependencies ‘reshape2’, ‘scales’, ‘Hmisc’
trying URL 'http://cran.rstudio.com/src/contrib/reshape2_1.4.1.tar.gz'
Content type 'application/x-gzip' length 34693 bytes (33 Kb)
opened URL
==================================================
downloaded 33 Kb
trying URL 'http://cran.rstudio.com/src/contrib/scales_0.2.4.tar.gz'
Content type 'application/x-gzip' length 40093 bytes (39 Kb)
opened URL
==================================================
downloaded 39 Kb
trying URL 'http://cran.rstudio.com/src/contrib/Hmisc_3.16-0.tar.gz'
Content type 'application/x-gzip' length 629536 bytes (614 …Run Code Online (Sandbox Code Playgroud)