繁体   English   中英

Windows小工具:如何从网页获取json并使用javascript转换为一系列数组?

[英]Windows Gadget: How do i get json from a webpage and convert to a series of arrays with javascript?

是否可以从网页获取JSON以用于Windows桌面小工具并通过javascript将其转换为数组?

一个例子就是优秀的。

现在回答很晚,但对其他人来说可能有用。 我正在开发Windows小工具,不能使用eval(字符串)的JSON.parse(字符串)将从服务器返回的字符串转换为json它根本不起作用,但我发现了一些奇怪的方法来做到这一点。

var json = (eval("[" + eval(json string) + "]"))[0]; //magic but works (btw creates json array as required in the question, all that required is to remove [0] in the end).

完整的代码示例:

function syncRequest(_url, _data) {
    var req = new XMLHttpRequest();
    req.open("POST", _url, false);
    req.setRequestHeader("Content-type", "application/json");
    req.send(_data);
    return req.responseText;
}

var response = syncRequest("http://...", "{json data}");

//here response converted into json
var json = (eval("[" + eval(response) + "]"))[0];

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM