问题描述
好的,所以我对编程很陌生,只学习了一些基本的C语言.
Alright so I am very new to programming and have only learned a little bit of basic C.
https://api.vircurex.com/api/get_info_for_1_currency.json?base=DOGE&alt=BTC
http://software.intel.com/en-us/html5/articles/how-to-access-JSON-data-in-HTML5-apps
http://jsbin.com/IQUjUkiX/1/edit
基本上我想做的是从" http://pastebin.com/4SPcTFbQ 中检索json. (链接1),并将其返回的数字存储在某种变量中. (有点像使用scanf()检索数字并将其存储到变量中)
Basically what I want to do is retrieve the json from "http://pastebin.com/4SPcTFbQ"(Link 1) and store on of the numbers it returns in some sort of variable. (kind of like using scanf() to retrieve the number and store it to a variable)
根据我一直在研究的内容,它不能通过C来完成,我相信必须通过javascript来完成.他们在这个网站上(请参阅pastebin链接2),提供了此示例(请参阅pastebin链接3),但是当我尝试将其示例json换成vircurex时,它似乎不再起作用.
From what I have been researching it cannot be done through C and I believe has to be done through javascript. On this site (refer to pastebin Link 2) they provide this example, (refer to pastebin Link 3) but when I try to swap out their example json for the vircurex one it does not seem to work anymore.
非常感谢任何帮助!
这里是示例:
HTML
<h3>Get JSON with padding</h3>
<button onclick="doJSON1()">Get JSON</button>
<br>
<br>
<hr>
<h3>Get JSON with Access-Control-Allow-Origin header: *</h3>
<button onclick="doJSON2()">Get JSON</button>
<br>
<br>
<hr>
<h3>Get JSON with NO Access-Control-Allow-Origin header</h3>
<button onclick="doJSON3()">Get JSON</button>
JavaScript
Javascript
function doJSON1() {
$.getJSON('http://time.jsontest.com/?alloworigin=false&callback=?', function (data) {
alert(JSON.stringify(data))
});
}
function doJSON2() {
$.getJSON('http://time.jsontest.com/?alloworigin=true', function (data) {
alert(JSON.stringify(data))
});
}
function doJSON3() {
$.getJSON('http://time.jsontest.com/?alloworigin=false', function (data) {
alert(JSON.stringify(data))
});
}
在 jsFiddle
推荐答案
示例,请参见Javascript的 var
用于声明变量.
Example, see Javascript's var
for declaring variables.
HTML
<h3>Get JSON with padding</h3>
<button id="ex1">Get JSON</button>
<br>
<br>
<hr>
<h3>Get JSON with Access-Control-Allow-Origin header: *</h3>
<button id="ex2">Get JSON</button>
<br>
<br>
<hr>
<h3>Get JSON with NO Access-Control-Allow-Origin header</h3>
<button id="ex3">Get JSON</button>
JavaScript
Javascript
var data1,
data2,
data3;
function doJSON1() {
$.getJSON('http://time.jsontest.com/?alloworigin=false&callback=?', function (data) {
data1 = data;
console.log(data1);
});
}
function doJSON2() {
$.getJSON('http://time.jsontest.com/?alloworigin=true', function (data) {
data2 = data;
console.log(data3);
});
}
function doJSON3() {
$.getJSON('http://time.jsontest.com/?alloworigin=false', function (data) {
data3 = data;
console.log(data3);
});
}
$('#ex1').on('click', doJSON1);
$('#ex2').on('click', doJSON2);
$('#ex3').on('click', doJSON3);
在 jsFiddle
这篇关于通过JSON检索数字并将其存储在变量中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!