我想知道是否有一个网页/软件可以将 Json 提要对象“翻译”为具有属性的 Java 对象。
例如 :
{
'firstName': 'John',
'lastName': 'Smith',
'address': {
'streetAddress': '21 2nd Street',
'city': 'New York'
}
}
会成为:
class Person {
private String firstName;
private String lastName;
private Address address;
public String getFirstName() { return firstName; }
public String getLastName() { return lastName; }
public Address getAddress() { return address; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public void setAddress(Address address) { this.address = address; }
public String toString() {
return String.format("firstName: %s, lastName: %s, address: [%s]", firstName, lastName, address);
}
}
class Address {
private String streetAddress;
private String city;
public String getStreetAddress() { return streetAddress; }
public String getCity() { return city; }
public void setStreetAddress(String streetAddress) { this.streetAddress = streetAddress; }
public void setCity(String city) { this.city = city; }
public String toString() {
return String.format("streetAddress: %s, city: %s", streetAddress, city);
}
}
我不是因为我很懒才问这个,但是我想解析的 JSON 有很多属性。