这是我的代码,我可以得到像status这样的字符串,但是例如“proxy”我不能,因为它在“8.8.8.8”中,我的问题是,如何用gson获得“proxy”的值。
{
"status": "ok",
"8.8.8.8": {
"asn": "AS15169",
"provider": "Google LLC",
"continent": "North America",
"country": "United States",
"isocode": "US",
"latitude": 37.751,
"longitude": -97.822,
"proxy": "no",
"type": "Business"
}
}
public static void main(String[] args) {
URL url = null;
try {
url = new URL("https://proxycheck.io/v2/8.8.8.8?vpn=1&asn=1&tag=proxycheck.io");
URLConnection request = url.openConnection();
request.connect();
JsonParser jp = new JsonParser();
JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent()));
System.out.println(root);
JsonObject rootobj = root.getAsJsonObject();
JsonElement proxy = rootobj.get("8.8.8.8");
System.out.println(proxy);
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
2条答案
按热度按时间3j86kqsm1#
您可以从json对象获取“8.8.8.8”中的“proxy”字段,如下所示:
退货:
不
完整示例:
piok6c0g2#