It is currently June 29th, 2022, 11:08 pm

Help parsing JSON objects with WebParser

Get help with creating, editing & fixing problems with skins
Kyremi
Posts: 41
Joined: September 22nd, 2011, 1:03 pm

Help parsing JSON objects with WebParser

Post by Kyremi »

Hey all,
I'm attempting to re-write my weather widget since I've moved location... the current live data I can find is provided by wunderground.com as a JSON file. Specifically, I need to extract some sunrise and sunset times which are presented as:

Code: Select all

"moon_phase": {
		"percentIlluminated":"1",
		"ageOfMoon":"29",
		"current_time": {
		"hour":"15",
		"minute":"31"
		},
		"sunrise": {
		"hour":"8",
		"minute":"00"
		},
		"sunset": {
		"hour":"18",
		"minute":"38"
		}
Currently if I put in .*"hour":"(.*), it gives me a result of 15, which makes sense, but it's not quite what I need. I tried a few things but none of them enabled me to 'enter' the "sunrise" and "sunset" objects...

Cheers for any help :)
User avatar
jsmorley
Developer
Posts: 22526
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help parsing JSON objects with WebParser

Post by jsmorley »

Code: Select all

[MeasureSite]
Measure=Plugin
Plugin=WebParser.dll
URL=file://#CURRENTPATH#Test.txt
RegExp=(?siU)percentilluminated":"(.*)".*ageOfMoon":"(.*)".*current_time.*hour":"(.*)".*minute":"(.*)".*sunrise.*hour":"(.*)".*minute":"(.*)".*sunset.*hour":"(.*)".*minute":"(.*)"
UpdateRate=600

[MeasurePercentIlluminated]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=1

[MeasureAgeOfMoon]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=2

[MeasureCurrentHour]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=3

[MeasureCurrentMinute]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=4

[MeasureSunriseHour]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=5

[MeasureSunriseMinute]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=6

[MeasureSunsetHour]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=7

[MeasureSunsetMinute]
Measure=Plugin
Plugin=WebParser.dll
URL=[MeasureSite]
StringIndex=8

Code: Select all

01=> 1
02=> 29
03=> 15
04=> 31
05=> 8
06=> 00
07=> 18
08=> 38
Kyremi
Posts: 41
Joined: September 22nd, 2011, 1:03 pm

Re: Help parsing JSON objects with WebParser

Post by Kyremi »

Ahh excellent, that's perfect. thanks :D Now I know the syntax for parsing nested JSON stuff :)
User avatar
jsmorley
Developer
Posts: 22526
Joined: April 19th, 2009, 11:02 pm
Location: Fort Hunt, Virginia, USA

Re: Help parsing JSON objects with WebParser

Post by jsmorley »

Kyremi wrote:Ahh excellent, that's perfect. thanks :D Now I know the syntax for parsing nested JSON stuff :)
You are welcome.

I left in an extra (?siU) that you can remove.