【发布时间】:2020-04-16 04:25:07
【问题描述】:
这是由 REST API 返回的:[[5671, 204], [5673, 192], [5674, 120], [5683, 120], [5684, 192], [5685, 204]]
当我在执行 typeof 时,我会在 javascript 中获取上面的字符串。我想把它转换成一个多维数组。
<script type="text/javascript">
const Http = new XMLHttpRequest();
const url='/hello/get_pw_status';
Http.open("GET", url);
Http.send();
var resp;
Http.onreadystatechange = (e) => {
console.log(Http.responseText);
document.getElementById("demo").innerHTML =Http.responseText;
console.log(typeof Http.responseText);
var pw_data = [];
pw_data=Http.data;
console.log(pw_data);
}
【问题讨论】:
-
var resp = JSON.parse(Http.responseText);并使用 resp 作为您的数据源
-
它正在工作,但在控制台中我可以看到下面的异常
标签: javascript rest api multidimensional-array xmlhttprequest