我正在使用下面的JSON字符串设计一个类。我稍后将使用GSON来读取JSON字符串。我在设计课程时遇到了麻烦。我尝试了太多版本,但没有一个返回所需的结果。显然,我没有正确地设计课程。我的应用程序代码非常复杂,所以我不能在这里粘贴它。我只是需要帮助来弄清楚我的班级设计,因为我已经尝试了太多次而没有成功。因为我对Java非常陌生,所以请放轻松。请。
JSON字符串:
{"info": [{"name":"Cineplex Outlets","storeCode":"3001","deptID":"5630","location":"Singapore","geography":"East","team_number":"Team 9",
"country":"United States","state":"Arizona","city":"Phoenix","address":{"storeAdd":["123,East Park St","1811 Fountain View","Pheoniz,
Arizona, 91210","United States"]},"passcode":"1001","telephone":{"landline":"1-818-502 8310"},"operationTimings":{"Monday":"10:00AM - 9:00PM",
"Tuesday":"10:00AM - 9:00PM","Friday":"10:00AM - 9:00PM","Wednesday":"10:00AM - 9:00PM","Thursday":"10:00AM - 9:00PM","Sunday":"11:00AM - 7:00PM",
"Saturday":"10:00AM - 9:00PM"},"links":{"myStInfo":"http://www.xyz","appointments":"http://abc",
"directions":"http://pqr"},"picture":{"http":"http://azy","https":"https://bbj"}}
Java类:
public class MyClass {
private String name;
private String storeCode;
private Long deptID;
private String location;
private String geography;
private String team_number;
private String country;
private String state;
private String city;
private Address address;
public static class MyClassTest
{
private ArrayList<MyClass> info;
private String passcode;
private Telephone telephone;
private Hours operationTimings;
private StoreUrl links;
private StoreImage picture;
}
public static class Address
{
private ArrayList<String> storeAdd;
}
public static class Telephone
{
private String telephone;
}
public static class Hours
{
private String Monday;
private String Tuesday;
private String Friday;
private String Wednesday;
private String Thursday;
private String Sunday;
private String Saturday;
}
public static class StoreUrl
{
private URL myStInfo;
private URL appointments;
private URL directions;
}
public static class StoreImage
{
private URL http;
private URL https;
}
}
答案 0 :(得分:0)
类电话的属性名称是固定电话,而不是电话。主类T1只有一个属性 info ,并且是一个String数组。你错过了Json string“]}”。
public class T1
{
public ArrayList<T2> info;
}
public class T2
{
public String name;
public String storeCode;
public String deptID;
public String location;
public String geography;
public String team_number;
public String country;
public String state;
public String city;
public Address address;
public String passcode;
public Telephone telephone;
public OperationTime operationTimings;
public Links links;
public Picture picture;
}
public class Address
{
public ArrayList<String> storeAdd;
}
public class Telephone
{
public String landline;
}
public class OperationTime
{
public String Monday;
public String Tuesday;
public String Friday;
public String Wednesday;
public String Thursday;
public String Sunday;
public String Saturday;
}
public class Links
{
public String myStInfo;
public String appointments;
public String directions;
}
public class Picture
{
public String http;
public String https;
}