I have a very simple json data file I’m reading from a url.
That bit works no problem when I run the code below in scriptable.
Here is the result.
{"SOC":">98.12%","TIME":"14:18:59"}
I’m trying to extract the SOC value and the TIME value into variables so I can display them in a widget but I can’t figure out how to do it in scriptable.
I have a little Hello World app working so it’s just the extraction bit I’m stuck on.
The data comes from my Raspberry Pi so I hope I have the json format correct. It will only ever be a single row of data.
//
let url = "http://192.168.5.106/test/output.json"
if (url != null) {
// We have a URL so we attempt to load the JSON.
let r = new Request(url)
let json = await r.loadJSON()
var myArray = JSON.stringify(json)
await QuickLook.present(myArray)
for (var soc of myArray)
{
await QuickLook.present(soc.SOC)
}
} else {
// We didn't get a valid input.
let alert = new Alert()
alert.title = "No valid input"
alert.message = "There was no URL or text argument provided."
alert.addCancelAction("OK")
await alert.present()
}