-5
{
  "status": "success",
  "description": "Data successfully received.",
  "data": {
    "geo": {
      "host": "2405:204:3213:5500:b012:b9d5:e4db:47b6",
      "ip": "2405:204:3213:5500:b012:b9d5:e4db:47b6",
      "rdns": "2405:204:3213:5500:b012:b9d5:e4db:47b6",
      "asn": "AS55836",
      "isp": "Reliance Jio Infocomm Limited ",
      "country_name": "India",
      "country_code": "IN",
      "region": "",
      "city": "",
      "postal_code": "",
      "continent_code": "AS",
      "latitude": "20",
      "longitude": "77",
      "dma_code": "",
      "area_code": "",
      "timezone": "Asia/Kolkata",
      "datetime": "2017-11-15 10:12:15"
    }
  }
}

How to read country_code using jQuery or JavaScript?

0

2 Answers 2

0

JSON.parse is what you are looking for.

let someJSObject = JSON.parse(someJSONString);

After that you can use the member access operator to access the fields you require.

Sign up to request clarification or add additional context in comments.

Comments

0

Here you go

var a = {
  "status": "success",
  "description": "Data successfully received.",
  "data": {
    "geo": {
      "host": "2405:204:3213:5500:b012:b9d5:e4db:47b6",
      "ip": "2405:204:3213:5500:b012:b9d5:e4db:47b6",
      "rdns": "2405:204:3213:5500:b012:b9d5:e4db:47b6",
      "asn": "AS55836",
      "isp": "Reliance Jio Infocomm Limited ",
      "country_name": "India",
      "country_code": "IN",
      "region": "",
      "city": "",
      "postal_code": "",
      "continent_code": "AS",
      "latitude": "20",
      "longitude": "77",
      "dma_code": "",
      "area_code": "",
      "timezone": "Asia/Kolkata",
      "datetime": "2017-11-15 10:12:15"
    }
  }
}

console.log("Country Code: "+ a.data.geo.country_code);

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.