From c3248699cf7a26000e5d32706b7f20a0742366dc Mon Sep 17 00:00:00 2001 From: pybple5kv <1766872402@qq.com> Date: Sun, 10 Jul 2022 22:19:13 +0800 Subject: [PATCH] ADD file via upload --- JsonParse.java | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 JsonParse.java 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; + } +}