This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Json and data
#2
(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  Big Grin

Just use json lib t
hen 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)
Reply


Messages In This Thread
Json and data - by tomnord - 15.03.2020, 17:02
RE: Json and data - by benanderson_475 - 15.03.2020, 21:14
RE: Json and data - by tomnord - 17.03.2020, 10:10
RE: Json and data - by benanderson_475 - 17.03.2020, 19:31
RE: Json and data - by AlexLV - 17.03.2020, 16:45
RE: Json and data - by Daniel - 17.03.2020, 17:03
RE: Json and data - by AlexLV - 17.03.2020, 19:57
RE: Json and data - by benanderson_475 - 17.03.2020, 20:03
RE: Json and data - by Daniel - 17.03.2020, 21:04
RE: Json and data - by AlexLV - 18.03.2020, 08:42
RE: Json and data - by Daniel - 18.03.2020, 08:53
RE: Json and data - by admin - 18.03.2020, 09:25

Forum Jump: