我正在尝试从中提取所有值 http://www.google.com/dictionary/json?callback=dic&q=keyword&sl=en&tl=en&restrict=pr%2Cde&client=te
我想使用GSON,但我无法弄清楚如何处理它。
有没有类似jericohtml解析器的东西可以简单地提取所有值?
另外,我需要使用java。 我可以检索json,但它不是经常编写的(我的意思是逐行编写)
感谢
URL u=new URL(url);
HttpURLConnection conn = (HttpURLConnection) u.openConnection();
conn.setRequestMethod("GET");
conn.setRequestProperty("Accept", "application/atom+xml");
conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.2; rv:21.0) Gecko/20100101 Firefox/21.0");
BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
String temp=br.readLine();
String strJson=temp.substring("dic(".length(),temp.length()-",200,null)".length());
System.out.println(strJson);
答案 0 :(得分:1)
你可以通过gson来提取你的jsonobject并设置你的用户定义对象 例如click here
Gson gson = new Gson();
try {
BufferedReader br = new BufferedReader(
new FileReader("c:\\file.json"));
//convert the json string back to object
DataObject obj = gson.fromJson(br, DataObject.class);
System.out.println(obj);
} catch (IOException e) {
e.printStackTrace();
}