Hi!
I am trying to get data from a http request json response.
When I print out response.data in the console it prints out the response.
The same with resp. (var resp = JSON.parse(JSON.stringify(response.data)); )
But when I try to print out resp.dagar[0].veckodag I get “dagar is undefined”
I have tried in a lot of different ways but no luck. I used List Paths in JSON to get the JSON path.
Is there anyone that can point me in the right direction?
Thanks
plugin.Name = "Plugin";
plugin.OnChangeRequest = onChangeRequest;
plugin.OnConnect = onConnect;
plugin.OnDisconnect = onDisconnect;
plugin.OnPoll = onPoll;
plugin.OnSynchronizeDevices = onSynchronizeDevices;
plugin.PollingInterval = 1000;
plugin.DefaultSettings = {};
function onChangeRequest(device, attribute, value) {
switch (attribute) {
case "Switch":
device.Switch = value;
break;
default:
break;
}
}
function onConnect() {
console.log("connected");
}
function onDisconnect() {
console.log("disconnected");
}
function onPoll() {
console.log("polling");
var http = new HTTPClient();
try {
var response = http.get("https://sholiday.faboul.se/dagar/v2.1/",{responseType : "text"});
} catch(err) {
console.log(err.message);
}
var resp = JSON.parse(JSON.stringify(response.data));
console.log(resp.dagar[0].veckodag);
}
function onSynchronizeDevices() {
var virtualSwitch = new Device();
virtualSwitch.Id = "1";
virtualSwitch.DisplayName = "Virtual Switch";
virtualSwitch.Capabilities = ["Switch"];
virtualSwitch.Attributes = [];
plugin.Devices[virtualSwitch.Id] = virtualSwitch;
}