diff --git a/JsonParse.java b/JsonParse.java new file mode 100644 index 0000000..36de7ec --- /dev/null +++ b/JsonParse.java @@ -0,0 +1,29 @@ +package com.example; + +import com.example.bean.QuestBean; +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +import java.lang.reflect.Type; +import java.util.List; + +public class JsonParse { + private static JsonParse instance; + private JsonParse(){ + } + public static JsonParse getInstance(){ + if(instance == null){ + instance = new JsonParse(); + } + return instance; + } + public ListgetShopList(String json){ + Gson gson = new Gson();//使用gson库解析JSON数据 + //创建一个TypeToken的匿名子类对象,并调用对象的getType()方法 + Type listType = new TypeToken>(){ + }.getType(); + //把获取到的信息集合存到shopList中、 + ListshopList = gson.fromJson(json,listType); + return shopList; + } +}