AndroidStudio插件之GsonOrXmlFormat
GsonOrXmlFormat下载链接
首先,谈谈开发这个插件的原因。在做android 客户端获取服务器数据,采用当下流行json格式,但是也有很多还残留着xml字符串格式,对于后台返回的xml/json的字符串不得不自己手动编写json/xml格式->bean 类。这个过程是枯燥而且乏味,有时候还容易出错,所以希望GsonOrXmlFormat帮你完成json/xml ->bean类的生成(quickly to convert a JSON string or XML string to an entity class)。提高开发效率.
首先要感谢dim轻微的GsonFormat描述
基于GsonFormat 集成了xml格式一>bean类
如何使用该插件呢
1.接下是安装插件,然后restart。
![YY2WY_CC7$V8K2N]DZR5QV.jpg](http://upload-images.jianshu.io/upload_images/1965893-7666ed35d739ac19.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
2.使用插件,在类的里面,点击右键Generate->GsonOrXmlFormat
![VL5FL3NOIJB`CET7Q38G]B.jpg](http://upload-images.jianshu.io/upload_images/1965893-de0e80b395bc2112.jpg?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240)
把xml报文黏贴进去如下图:
3.效果
生成的bean类如下
public class Test {
/**
* employee : {"sex":"m","name":"ddviplinux","age":30}
*/
private EmployeesBean employees;
public EmployeesBean getEmployees() {
return employees;
}
public void setEmployees(EmployeesBean employees) {
this.employees = employees;
}
public static class EmployeesBean {
/**
* sex : m
* name : ddviplinux
* age : 30
*/
private EmployeeBean employee;
public EmployeeBean getEmployee() {
return employee;
}
public void setEmployee(EmployeeBean employee) {
this.employee = employee;
}
public static class EmployeeBean {
private String sex;
private String name;
private int age;
public String getSex() {
return sex;
}
public void setSex(String sex) {
this.sex = sex;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public int getAge() {
return age;
}
public void setAge(int age) {
this.age = age;
}
}
}
}
同理json->bean类,也是如此呀~O(∩_∩)O哈哈