Last active
August 29, 2015 14:02
-
-
Save ongakuer/b531b3de0d389463e1fe to your computer and use it in GitHub Desktop.
proguard混淆后导致json解析出错
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private void parseJson() { | |
String json = "{\"school\":{\"classes\": [{\"name\":\"one\",\"count\":1},{\"name\":\"two\",\"count\":2}],\"headMaster\" : \"Einstein\"}}"; | |
ObjectMapper mapper = new ObjectMapper(); | |
try { | |
ResponseModle response = mapper.readValue(json, ResponseModle.class); | |
Log.e(this.getClass().getName(), "headMaster : " + response.getSchool().getHeadMaster()); | |
Log.e(this.getClass().getName(), "class name : " | |
+ response.getSchool().getClasses().get(0).getName()); | |
} catch (JsonParseException e) { | |
e.printStackTrace(); | |
} catch (JsonMappingException e) { | |
e.printStackTrace(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
// 混淆后抛错 | |
// java.util.LinkedHashMap cannot be cast to me.relex.jsonparse.modle.ClassModle | |
// | |
// 需要在proguard中加入 | |
// -keepattributes Signature | |
// | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ResponseModle { | |
private SchoolModle school; | |
public SchoolModle getSchool() { | |
return school; | |
} | |
public void setSchool(SchoolModle school) { | |
this.school = school; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class SchoolModle { | |
private List<ClassModle> classes; | |
private String headMaster; | |
public List<ClassModle> getClasses() { | |
return classes; | |
} | |
public void setClasses(List<ClassModle> classes) { | |
this.classes = classes; | |
} | |
public String getHeadMaster() { | |
return headMaster; | |
} | |
public void setHeadMaster(String headMaster) { | |
this.headMaster = headMaster; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ClassModle { | |
private String name; | |
private int count; | |
public String getName() { | |
return name; | |
} | |
public void setName(String name) { | |
this.name = name; | |
} | |
public int getCount() { | |
return count; | |
} | |
public void setCount(int count) { | |
this.count = count; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment