如何获取此字符串并将其放入String Array或HashMap?任何参考?将JSON字符串反序列化为字符串数组
{
"code" : 403,
"errors" : [ {
"domain" : "global",
"location" : "Authorization",
"locationType" : "header",
"message" : "The domain policy has disabled third-party Drive apps",
"reason" : "domainPolicy"
} ],
"message" : "The domain policy has disabled third-party Drive apps"
}
====
这是我对杰克逊的解决方案:
public class TheErrorModel {
public int code;
public Collection<Error> errors;
public String message;
public TheErrorModel() {
}
public TheErrorModel(String json)
throws Exception {
ObjectMapper mapper = new ObjectMapper();
TheErrorModelother = mapper.readValue(json, TheErrorModel.class);
this.code = other.code;
this.errors = other.errors;
this.message = other.message;
}
}
class Error {
public String domain;
public String location;
public String locationType;
public String message;
public String reason;
}
TheErrorModel theErrorModel = new TheErrorModel(json);
所以我得到的东西像theErrorModel.message:d
有很多libs在线提供。你有尝试过吗? –
我有杰克逊,但我不知道使用它的想法是什么:/ – lannyboy
http://www.mkyong.com/java/how-to-convert-java-object-to-from-json-jackson/ –