Android: how to get the value of gson linkedtreemap?

I tried to simply get the value from my gson object, so in my "city" object:

I need to get the name "first" and Boolean value from "is selected"

I just wrote a new class "keypairbooldata":

class KeyPairBoolData {
    int id;
    String name;
    boolean isSelected;

}

But I don't know what I should write in the new class to get these values. This is the value I'm trying to get:

List<KeyPairBoolData> city = gson.fromJson(myListArray, listArray.getClass());

Any ideas? thank you!

resolvent:

Try this:

Method to deserialize a generic collection:

Type listType = new TypeToken<ArrayList<KeyPairBoolData>>() {
                    }.getType();
List<KeyPairBoolData> keyPairBoolDataList = new Gson().fromJson(jsonArray, listType);

Import: import java.lang.reflect.type;

https://stackoverflow.com/a/5554296/4848308 Your answer

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>