Windows gadget: how do I get json from a webpage and convert to a series of arrays using javascript?

Is it possible to get JSON from a web page for use in gadgets on a Windows desktop and convert them to an array through javascript?

An example would be great.

+3
source share
2 answers

Check out this blog post Creating a Windows Sidebar Gadget for an example.

+2
source

, - . Windows JSON.parse(string) eval (string) , 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];
0

Source: https://habr.com/ru/post/1783933/


All Articles