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.
24 lines
529 B
24 lines
529 B
package xyz.fycz.myreader.util;
|
|
|
|
import com.google.gson.Gson;
|
|
|
|
import org.json.JSONArray;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
|
|
public class JsonArrayToObjectArray {
|
|
|
|
public static <T> ArrayList<T> getArray(String json, Class<T> c) throws Exception {
|
|
ArrayList<T> arrayList = new ArrayList<>();
|
|
|
|
JSONArray jsonArray = new JSONArray(json);
|
|
for (int i = 0; i < jsonArray.length(); i++) {
|
|
arrayList.add(new Gson().fromJson(jsonArray.getString(i), c));
|
|
}
|
|
|
|
return arrayList;
|
|
}
|
|
|
|
}
|
|
|