我有一些看起来像这样的JSON数据:
[["Rank", "Team", "Qual Avg", "Auto", "Container", "Coopertition", "Litter", "Tote", "Played"],
["1", "1225", "60.8", "0", "224", "80", "70", "240", "10"],
["2", "3506", "55.2", "0", "132", "40", "268", "118", "10"],
["3", "5511", "53.3", "4", "124", "160", "141", "134", "10"],
["4", "3336", "51.7", "0", "80", "160", "177", "100", "10"],
["5", "4073", "49.1", "0", "100", "80", "167", "156", "10"]]
我一直在使用GSON库来解析其他JSON数据没有问题,但由于这些数组没有名称。我不确定如何为此制作模型,因为没有任何名称。我的抓取脚本就是这样的。我确信有一些简单的东西我不知道但是在文档中找不到任何有用的东西。
public class EventParsers {
public String TAG = "EventParsers";
public volatile boolean parsingComplete = true;
private Events[] events;
private ArrayList<Events> eventArray = new ArrayList<>();
public void fetchJSON(final String number) {
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
try {
Gson gson = new Gson();
BlueAlliance blueAlliance = new BlueAlliance();
BufferedReader reader = new BufferedReader(new InputStreamReader(blueAlliance
.connect(Constants.getEventURL(number))));
events = gson.fromJson(reader, Events[].class);
eventArray = new ArrayList<>(Arrays.asList(events));
blueAlliance.close();
Log.i(TAG, "URL: " + Constants.getEventURL(number));
parsingComplete = false;
} catch (Exception e) {
e.printStackTrace();
}
}
});
thread.start();
}
public ArrayList<Events> getEvents() {
return eventArray;
}
}
答案 0 :(得分:1)
实际上你有一系列字符串数组,所以你需要的只是
events = gson.fromJson(reader, String[][].class);