Код: Выделить всё
private static final String URLSTRING_2 = "http://freegeoip.net/json/";
Если я анализирую JSON и я пытаюсь получить значение для ключа "Country_name", то фрагмент печатает, как и ожидалось, «Сингапур» < /p>
public static void main(String[] args) throws Exception {
// Connect to the URL using java's native library
final URL url = new URL(URLSTRING_2);
final HttpURLConnection request = (HttpURLConnection) url.openConnection();
request.connect();
// Convert to a JSON object to print data
final JsonParser jp = new JsonParser(); // from gson
final JsonElement root = jp.parse(new InputStreamReader((InputStream) request.getContent())); // Convert the input stream to a json
// element
final JsonObject rootobj = root.getAsJsonObject(); // May be an array, may be an object.
final String country = rootobj.get("country_name").getAsString(); // just grab the zipcode
System.out.println("country_name: " + country);
}
< /code>
Теперь мой вопрос: < /h1>
Если я сделаю то же самое с этой ссылкой
https://api.stackexchange.com//2.2/user ... iwkfwpol5g my browser выводит следующие json:
Подробнее здесь: https://stackoverflow.com/questions/361 ... change-api