2017-11-15 2 views
-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" 
    } 
    } 
} 

로 도와주세요 JQuery와 또는 자바 스크립트를 사용하여 JSON 데이터에서 COUNTRY_CODE를 읽는 방법을 어떻게 JQuery와 또는 자바 스크립트를 사용하여 country_code를 읽을 수 있습니다. 도와주세요.가능한 한 빨리

답변

1

JSON.parse가 당신이 찾고있는 것입니다.

let someJSObject = JSON.parse(someJSONString); 

그런 다음 멤버 액세스 연산자를 사용하여 필요한 필드에 액세스 할 수 있습니다. 여기

0

당신은

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);

이동