質問

I am using GSON to deserialize a JSON string.

mGSON.fromJson(json, mClass)  //mClass == ClassA.class

The problem comes in when using the class below

public class BaseModel<T> {
    String StatusCode, Description;
    T Data;
}

I'd like to do something like this

mGSON.fromJson(json, mClass<DataClass>);

or

mGSON.fromJson(json, (BaseModel<DataClass>).class);

but obviously this doesn't work.

役に立ちましたか?

解決

Try and:

mGSON.fromJson(json, new TypeToken<BaseModel<DataClasss>>() {});

See here for more information.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top