简体   繁体   English

如何使用jQuery从URL解析JSON数据

[英]how to parse json data from url using jquery

I need to parse json data from the url 我需要解析url中的json数据

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

and i need the value for "USDAED" and assign it to input. 我需要"USDAED"的值并将其分配给输入。

{
  "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; 您可以使用$.getJSON()获取数据,使用.val()输入值;

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'/>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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