0
我想將從紐約時報返回的數據保存到一個數組中。對於結果的每一頁,紐約時報API返回一個包含10個對象的新數組。因此,JSONArray results
只是多個數組的集合。這使我很難saveJSONArray results
,因爲它只保存一個數組(其中有10個objets)。什麼是最好的解決方案?我如何將所有JSONObjects解析到一個數組中?謝謝!如何在處理中使用紐約時報API處理JSON對象和JSON數組
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");
}