문제

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