Answer the question
In order to leave comments, you need to log in
How to parse response to variables?
Hello, how to take out in variables from the Json result in this code
<html>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js"></script>
<script type='text/javascript'>
$.getJSON('http://ip-api.com/json?callback=?',
function(data) {
console.log(JSON.stringify(data, null, 2));
});
</script>
</body>
</html>
{
"as": "AS41794 Sibirskie Seti Ltd.",
"city": "Barnaul",
"country": "Russia",
"countryCode": "RU",
"isp": "Sibirskie Seti Ltd.",
"lat ": 53.36,
"lon": 83.76,
"org": "Sibirskie Seti Ltd.",
"query": "5.44.170.141",
"region": "ALT",
"regionName": "Altai Krai",
"status ": "success",
"timezone": "Asia/Barnaul",
"zip": "656000"
}
Answer the question
In order to leave comments, you need to log in
es2015 offers destructuring for such cases
$.getJSON(
'http://ip-api.com/json?callback=?',
function({city, ip, county, ...others}) {
/*...*/
}
);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question