javascript json对象转成数组
json对象:{"data":[[1,3.0],[2,3.9],[3,2.0],[4,1.2],[5,1.3],[6,2.5],[7,2.0],[8,3.1],[9,2....
json对象:
{
"data": [[1, 3.0], [2, 3.9], [3, 2.0], [4, 1.2], [5, 1.3], [6, 2.5], [7, 2.0], [8, 3.1], [9, 2.9], [10, 0.9]]
}
获取json对象
$(document).ready(function () {
function onDataReceived(series) {
if (!alreadyFetched[series.label]) {
alreadyFetched[series.label] = true;
data.push( series);
};
}
$.ajax({
url: "1.json",
type: "GET",
dataType: "JSON",
success: onDataReceived
});
怎样让得到的数据data等同于
var data= [[1, 3.0], [2, 3.9], [3, 2.0], [4, 1.2], [5, 1.3], [6, 2.5], [7, 2.0], [8, 3.1], [9, 2.9], [10, 0.9]]
获取json文件的源代码:
var data = [];
var alreadyFetched = {};
$(document).ready(function () {
function onDataReceived(series) {
if (!alreadyFetched[series.label]) {
alreadyFetched[series.label] = true;
data.push( series);
};
}
$.ajax({
url: "2.json",
type: "GET",
dataType: "json",
success: onDataReceived
});
}); 展开
{
"data": [[1, 3.0], [2, 3.9], [3, 2.0], [4, 1.2], [5, 1.3], [6, 2.5], [7, 2.0], [8, 3.1], [9, 2.9], [10, 0.9]]
}
获取json对象
$(document).ready(function () {
function onDataReceived(series) {
if (!alreadyFetched[series.label]) {
alreadyFetched[series.label] = true;
data.push( series);
};
}
$.ajax({
url: "1.json",
type: "GET",
dataType: "JSON",
success: onDataReceived
});
怎样让得到的数据data等同于
var data= [[1, 3.0], [2, 3.9], [3, 2.0], [4, 1.2], [5, 1.3], [6, 2.5], [7, 2.0], [8, 3.1], [9, 2.9], [10, 0.9]]
获取json文件的源代码:
var data = [];
var alreadyFetched = {};
$(document).ready(function () {
function onDataReceived(series) {
if (!alreadyFetched[series.label]) {
alreadyFetched[series.label] = true;
data.push( series);
};
}
$.ajax({
url: "2.json",
type: "GET",
dataType: "json",
success: onDataReceived
});
}); 展开
展开全部
我平时是这样把json转换成数组循环处理的:
var dataArray=eval(jsonStr);
for(var i in dataArray)
{
//TODO
}
有什么问题你都可以追问我,没问题,望采纳,谢谢!
更多追问追答
追问
谢谢,补充了问题,帮忙再看下
追答
你可以把ajax请求的数据类型修改一下啊:
dataType: "JSON",
这个改成返回字符串:
dataType: "TXT",
然后在需要使用的地方eval(returnData);就可以了!
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询