Quantcast
Channel: Rainmeter Forums
Viewing all articles
Browse latest Browse all 612

Community Tips & Tricks • Parsing JSON API

$
0
0
I just found this and decided to try it out. It took me a while to make it work since I've never used LUA. Everything is working, but minor changes were needed to get it to run. My code looks like this:

scrape.lua

Code:

function Initialize()json = dofile( SKIN:GetVariable( '@' )..'json.lua' )scraperData = SKIN:GetMeasure( "WebScraper" )endfunction Update()data = json.decode( scraperData:GetStringValue() )SKIN:Bang( '!SetOption', 'meterSunriseTime', 'Text', 'Sunrise: '..data[ 'sunrise' ] )SKIN:Bang( '!SetOption', 'meterSunSetTime', 'Text', 'Sunset: '..data[ 'sunset' ] )SKIN:Bang( '!SetOption', 'meterPowerballJackpot', 'Text', 'Jackpot: '..data[ 'pbjack' ] )SKIN:Bang( '!SetOption', 'meterPowerballCash', 'Text', 'Cash Value: '..data[ 'pbcash' ] )SKIN:Bang( '!SetOption', 'meterMegaMillionsJackpot', 'Text', 'Jackpot: '..data[ 'mmjack' ] )SKIN:Bang( '!SetOption', 'meterMegaMillionsCash', 'Text', 'Cash Value: '..data[ 'mmcash' ] )end
I am getting an error logged:

Code:

Script: json.lua:185: unexpected character '' at line 1 col 1
I am loading the JSON file at https://n5dkj.radio/time/webdata.json. The error does not keep the meters from updating correctly.

Statistics: Posted by n5dkj — Yesterday, 2:38 pm — Replies 2 — Views 3551



Viewing all articles
Browse latest Browse all 612

Trending Articles