2010-05-28 27 views

cevap

16

HtmlUnit bunu desteklemiyor. En yüksek bir JS işlevini çalıştırabilir. Geri verilen yanıtın Content-Type değeri application/json ile eşleşiyorsa ve daha sonra ayrıştırmak için uygun aracı kullanırsa, önceden kontrol etmeniz gerekir. Google Gson bu konuda yararlıdır. JSON yapısı önceden biliniyorsa

WebClient client = new WebClient(); 
Page page = client.getPage("https://stackoverflow.com/users/flair/97901.json"); 
WebResponse response = page.getWebResponse(); 
if (response.getContentType().equals("application/json")) { 
    String json = response.getContentAsString(); 
    Map<String, String> map = new Gson().fromJson(json, new TypeToken<Map<String, String>>() {}.getType()); 
    System.out.println(map.get("displayName")); // Benju 
} 

, hatta fullworthy Javabean dönüştürmek için GSON kullanabilirsiniz. this answer'da bir örnek bulabilirsiniz.