You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
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 List < QuestBean > getShopList ( String json ) {
Gson gson = new Gson ( ) ; //使用gson库解析JSON数据
//创建一个TypeToken的匿名子类对象, 并调用对象的getType()方法
Type listType = new TypeToken < List < QuestBean > > ( ) {
} . getType ( ) ;
//把获取到的信息集合存到shopList中、
List < QuestBean > shopList = gson . fromJson ( json , listType ) ;
return shopList ;
}
}