GetJSON的数据:需要澄清 [英] GetJSON's data : clarification needed
本文介绍了GetJSON的数据:需要澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
给出的JSON包含:
[
{"myKey":"A","status":0,"score":1.5},{"myKey":"C","status":1,"score":2},
{"myKey":"D","status":0,"score":0.2},{"myKey":"E","status":1,"score":16},
{"myKey":"F","status":0,"score":0.4},{"myKey":"G","status":1,"score":3}
]
使用JS这样的
MyJSON = $.getJSON('http://d.codio.com/hugolpz/getJson--/App/data/statusStarter2.json' );
如何将JSON的内容(字符串化)放入localStorage.data中?
注意:localStorage.data = JSON.stringify(MyJSON);
返回{"readyState":1}
,这不是我的愿望.我查看了 jQuery.getJSON/,但对function (data)
感到很困惑.
Note: localStorage.data = JSON.stringify(MyJSON);
returns {"readyState":1}
, which is not my wish. I looked into jQuery.getJSON/, but I'am quite confused by the function (data)
.
推荐答案
getJSON
异步工作,返回的内容是AJAX请求对象.因此,请使用getJSON
的成功回调函数来接收数据
getJSON
works asynchronously and what it returns is AJAX request object. So use success callback function of getJSON
to recieve the data
$.getJSON('http://d.codio.com/hugolpz/getJson--/App/data/statusStarter2.json', function(data) {
// do JSON.stringify(data) here
});
这篇关于GetJSON的数据:需要澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文