1

これは私のJSON文字列です:

[{"BranchID":1,"SecurityCode1":13,"SecurityCode2":14,"PrintHeight":10,"PrintWidth":10,"Active":true}]

これは、JSONの解析に使用しているコードです。

Type t = new TypeToken<List<Setting>>() {
}.getClass();

String json =  ServiceHelper.getJSON(response); 
List<Setting> list = (List<Setting>) gson.fromJson(json, t); 
    //list is null which it souldnt

これは設定クラスであり、エンティティはORMDroidエンティティクラスです。

public class Setting extends Entity {

@Column(name = "id", primaryKey = true)
@SerializedName("BranchID")
public int BranchID;

public int securityCodeLPK;
public int securityCodeSDK;

@SerializedName("PrintHeight")
public int PrintHeight;

@SerializedName("PrintWidth")
public int PrintWidth;

@SerializedName("Active")
public String Active;

@SerializedName("SecurityCode1")
public String SecurityCode1;

@SerializedName("SecurityCode2")
public String SecurityCode2;

public Setting(int BranchID, int height, int width, String active, String securityCode1, String securityCode2) {
    super();
    BranchID = BranchID;
    PrintHeight = height;
    PrintWidth = width;
    Active = active;
    SecurityCode1 = securityCode1;
    SecurityCode2 = securityCode2;
}

public Setting () {
    super();
}

}

問題ないようですが、gson.FromJsonの後のリストはnullです。このコードの何が問題になっていますか?

助けてください

4

1 に答える 1

1

getType()の代わりに使用する必要がありgetClass()ます。

Type t = new TypeToken<List<Setting>>() {}.getType();
于 2013-03-08T16:44:23.037 に答える