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 のプロパティ名は、 telephoneではなくlandlineです。プリンシパル クラス T1 には、プロパティinfoが 1 つだけあり、String の配列です。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 に答える