我想知道如何解析一個JSON飼料的項目(如每個項目的URL /標題/描述)。我看過doc/api,但它沒有幫助我。解析與谷歌Gson的Json飼料
這是我走到這一步,
import com.google.gson.Gson;
import com.google.gson.JsonObject;
public class ImportSources extends Job {
public void doJob() throws IOException {
String json = stringOfUrl("http://feed.test/all.json");
JsonObject jobj = new Gson().fromJson(json, JsonObject.class);
Logger.info(jobj.get("responseData").toString());
}
public static String stringOfUrl(String addr) throws IOException {
ByteArrayOutputStream output = new ByteArrayOutputStream();
URL url = new URL(addr);
IOUtils.copy(url.openStream(), output);
return output.toString();
}
}
謝謝您的回答,我試圖例子適用於下列飼料:http://www.stocktwits.com/ streams/all.json。我沒有設法得到除null以外的任何其他值。我是否需要創建兩個組:流和推文? – Roch 2010-01-11 11:10:53