下面我试图创建一个列表,但是符号" Feed"无法解决。我应该包括哪些内容。我的想法是从我创建的文件中获取新闻文章。
public class Utils {
private static final String TAG = "Utils";
public static List<Feed> loadFeeds(Context context){
try{
GsonBuilder builder = new GsonBuilder();
Gson gson = builder.create();
JSONArray array = new JSONArray(loadJSONFromAsset(context, "news.json"));
List<Feed> feedList = new ArrayList<>();
for(int i=0;i<array.length();i++){
Feed feed = gson.fromJson(array.getString(i), Feed.class);
feedList.add(feed);
}
return feedList;
}catch (Exception e){
Log.d(TAG,"seedGames parseException " + e);
e.printStackTrace();
return null;
}
}
private static String loadJSONFromAsset(Context context, String jsonFileName) {
String json = null;
InputStream is = null;
try {
AssetManager manager = context.getAssets();
Log.d(TAG,"path "+jsonFileName);
is = manager.open(jsonFileName);
int size = is.available();
byte[] buffer = new byte[size];
is.read(buffer);
is.close();
json = new String(buffer, "UTF-8");
} catch (IOException ex) {
ex.printStackTrace();
return null;
}
return json;
}
}
*
答案 0 :(得分:0)
要创建List<Feed>
,您必须创建课程Feed
并将其导入Utils
课程。
答案 1 :(得分:0)
已经排序了。如果我的Feed.java类拼错了。请原谅我的笨蛋