简体   繁体   中英

how to parse json data from url using jquery

I need to parse json data from the url

http://www.apilayer.net/api/live?access_key=f40041...&format=1

and i need the value for "USDAED" and assign it to input.

{
  "success":true,
  "terms":"https:\/\/currencylayer.com\/terms",
  "privacy":"https:\/\/currencylayer.com\/privacy",
  "timestamp":1483594992,
  "source":"USD",
  "quotes":{
    "USDAED":3.672802,
    "USDAFN":66.699997,
    "USDALL":129.729996,
    "USDAMD":483.440002,
    "USDANG":1.76987,
    "USDAOA":165.078003,
    "USDARS":16.059999,
  }
}

You can use $.getJSON() to get data, the .val() to input value;

var URL = "http://www.example.com/...................."
$.getJSON(URL, function(d) {
  console.log(d.quotes.USDAED)
  $('#dummy').val(d.quotes.USDAED)
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id='dummy'/>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM