15.03.2020, 21:14
(15.03.2020, 17:02)tomnord Wrote: So, to pass time in an quarantine I'm looking into usefull and not so usefull scripts.
So far I've gotten som usefull stuff out of the way. Now for the fooling about scripts.
If I want to read data from a json table (if its called that), looking something like this:
{"confirmed":86,"dead":0,"recovered":0,"confirmedPer1kCapita":0.27991966956459474,"name":"Agder","countyCode":"42"},
How would I go about this?
I read the data from an url. I would like to get the numbers as local variables.
I'm sure it's an easy task, so just point me in the right direction
Just use json lib then access all data value/s from the decoded json like this dec.countycode, dec.name etc
Code:
require('json')
s = [[{"confirmed":86,"dead":0,"recovered":0,"confirmedPer1kCapita":0.27991966956459474,"name":"Agder","countyCode":"42"}]]
dec = json.decode(s)
log(dec.confirmed)