我正在尝试将从纽约时报返回的数据保存到一个数组中。对于每一页结果,The New York Times API 返回一个包含 10 个对象的新数组。结果,JSONArray results
只是多个数组的集合。这让我很难做到,saveJSONArray results
因为它只保存了一个数组(里面有 10 个对象)。什么是最好的解决方案?如何将所有 JSONObject 解析为一个数组?谢谢!
String baseURL = "http://api.nytimes.com/svc/search/v1/article";
String apiKey = "xxxxxxxxxxxxxxxxxxxxxxxxx:x:xxxxxx";
size(500, 300);
String beginDate = "19940101";
String endDate = "19960101";
String word = "O.J.+Simpson";
for (int i = 0; i < 150; i++) {
String request = baseURL + "?query=" + word + "&begin_date=" + beginDate + "&end_date=" + endDate + "&offset=" + i + "&api-key=" + apiKey;
i = i + 1;
String result = join(loadStrings(request), "");
JSONObject nytData = JSONObject.parse(result);
JSONArray results = nytData.getJSONArray("results");
//saveJSONArray(results, "data/new.json");
}