Using an IMP003, I am trying to use the JSON parser tool library but get the following error. “This might be a rookie mistake I am new to JSON”.
2016-06-19 00:35:27 UTC-4 [Agent] ERROR: the index 'slice' does not exist 2016-06-19 00:35:27 UTC-4 [Agent] ERROR: in parse ...imp#jsonparser.class.nut#1.0.0:285 2016-06-19 00:35:27 UTC-4 [Agent] ERROR: from getUbiDotsPwrBtn agent_code:505 2016-06-19 00:35:27 UTC-4 [Agent] ERROR: from main agent_code:823
This is the code I am using inside a function:
`#require "JSONParser.class.nut:1.0.0"
function getUbiDotsPwrBtn(){
local headers = { “Content-Type”: “GET”, “X-Auth-Token”: UBIDOTS_X_Auth_Token }; // Replace the token with yours
local url = “http://things.ubidots.com/api/v1.6/variables/<>/values/?page_size=1&token=<>”;
server.log(url);
local request = http.get(url, headers);
local response = request.sendsync();
result = JSONParser.parse(response);
server.log(result.count);
}`
The response being received is the following:
{ "count": 11, "next": "http://things.ubidots.com/api/v1.6/variables/57562c06762542450a5e5000/values/?token=i35cpIjr1KeRQvA4PC2zAIRwWfUENG&page=2&page_size=1", "previous": null, "results": [ { "url": "http://things.ubidots.com/api/v1.6/values/53861ce276254261831076bb", "value": 1.0, "timestamp": 1466309858069, "context": {}, "created_at": "2016-06-19T04:17:38.069" } ] }