0

我正在使用下面的 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;
}

}
4

1 回答 1

0

Telephone 类的属性名称是固定电话,而不是电话。主体类 T1,只有一个属性info,并且是一个字符串数组。您错过了 Json 字符串“]}”。

   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;
}
于 2013-07-20T05:16:44.853 回答