JavaScript json处理程序
我很难用简单的javascript(如果可能的话,没有jQuery)处理这个请求。 输入信息的屏幕截图: 目标是我需要将这些行分解为var:JavaScript json处理程序,javascript,json,Javascript,Json,我很难用简单的javascript(如果可能的话,没有jQuery)处理这个请求。 输入信息的屏幕截图: 目标是我需要将这些行分解为var: ["buy","1400595135855","8511315","0.007379"] 有人能帮我一下吗?你应该像这样迭代数组: var a = ["buy","1400595135855","8511315","0.007379"]; for (var i=0; i<a.length; i++) { console.log(a[i])
["buy","1400595135855","8511315","0.007379"]
有人能帮我一下吗?你应该像这样迭代数组:
var a = ["buy","1400595135855","8511315","0.007379"];
for (var i=0; i<a.length; i++) {
console.log(a[i])
}
// You'll need to figure out a way to fill in the '...' with your JSON string,
// probably with an AJAX call.
var jsonString = '...'
var jsonObj = JSON.parse(jsonString);
for (var i = 0; i < jsonObj.data.length; i++) {
// Here, we're iterating through the data array on the returned object.
var dataItem = jsonObj.data[i];
// You can now access properties of each data item using dataItem[<index>]
// and do whatever you need to with them.
}
var a=[“买入”、“140059513555”、“8511315”、“0.007379”];
对于(var i=0;i,由于嵌套数组似乎会让您感到困惑,因此这里有一个代码段将响应转换为对象数组
var response = {
e: 'history-update',
data: [["buy","1400595135855","8511315","0.007379"],
["buy","1400595135855","8511315","0.007379"]]
};
var result = response.data.map(function(item){
var ret = {};
for(var i = 0; i < item.length; i++)
ret['item_' + i] = item[i];
return ret;
});
console.log(result[0].item_0); // 'buy'
var响应={
e:‘历史更新’,
数据:[“购买”、“1400595135855”、“8511315”、“0.007379”],
[“购买”、“140059513555”、“8511315”、“0.007379”]]
};
var result=response.data.map(函数(项){
var ret={};
对于(变量i=0;i
我刚刚调用了属性项
。这对您有帮助吗
如果您希望将值存储在单个变量中,而不受仅在循环中或逐个使用它们的限制,这是一种方法。如果Json响应中的参数数量不总是相同,则循环更好
var a = ["buy","1400595135855","8511315","0.007379"];
var value1 = a[0];
var value2 = a[1];
var value3 = a[2];
var value4 = a[3];
我想您需要使用。您需要传入图像中显示的JSON字符串。如下所示:
var a = ["buy","1400595135855","8511315","0.007379"];
for (var i=0; i<a.length; i++) {
console.log(a[i])
}
// You'll need to figure out a way to fill in the '...' with your JSON string,
// probably with an AJAX call.
var jsonString = '...'
var jsonObj = JSON.parse(jsonString);
for (var i = 0; i < jsonObj.data.length; i++) {
// Here, we're iterating through the data array on the returned object.
var dataItem = jsonObj.data[i];
// You can now access properties of each data item using dataItem[<index>]
// and do whatever you need to with them.
}
//您需要找到一种用JSON字符串填充“…”的方法,
//可能需要一个AJAX调用。
var jsonString='…'
var jsonObj=JSON.parse(jsonString);
对于(var i=0;i
到目前为止你尝试了什么?我在stackoverflow和google上搜索了一些close,但这个“[[”让我很困惑……它只是一个数组中有一个数组的对象。你说“将这些行分解为var”是什么意思?@Johan他想把所有单个值转换成单个变量,就像charm一样!谢谢!