如何獲取此字符串並將其放入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/ –