Jump to content

Help with RegEx.Matches (VB.NET)


Damein
 Share

Recommended Posts

I've made good head way but I can't seem to figure out what I am doing wrong here.

I am pulling data from a webpage doing a JSON request for weather and then I am wanting to parse out each day separately so I can store it in a Class so I can then display it as needed. I've been able to pull the data and everything but I can't seem to loop through all the instances of the days.

 

Snippet of the JSON response

 

"epoch":"1478217600",
    "pretty":"7:00 PM CDT on November 03, 2016",
    "day":3,
    "month":11,
    "year":2016,
    "yday":307,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"November",
    "monthname_short":"Nov",
    "weekday_short":"Thu",
    "weekday":"Thursday",
    "ampm":"PM",
    "tz_short":"CDT",
    "tz_long":"America/Chicago"
},
        "period":2,
        "high": {
        "fahrenheit":"71",
        "celsius":"22"
        },
        "low": {
        "fahrenheit":"49",
        "celsius":"9"
        },
        "conditions":"Chance of a Thunderstorm",
        "icon":"chancetstorms",
        "icon_url":"http://icons.wxug.com/i/c/k/chancetstorms.gif",
        "skyicon":"",
        "pop":60,
        "qpf_allday": {
        "in": 0.10,
        "mm": 3
        },
        "qpf_day": {
        "in": 0.10,
        "mm": 3
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 15,
        "kph": 24,
        "dir": "NW",
        "degrees": 309
        },
        "avewind": {
        "mph": 11,
        "kph": 18,
        "dir": "NW",
        "degrees": 309
        },
        "avehumidity": 72,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{
    "epoch":"1478304000",
    "pretty":"7:00 PM CDT on November 04, 2016",
    "day":4,
    "month":11,
    "year":2016,
    "yday":308,
    "hour":19,
    "min":"00",
    "sec":0,
    "isdst":"1",
    "monthname":"November",
    "monthname_short":"Nov",
    "weekday_short":"Fri",
    "weekday":"Friday",
    "ampm":"PM",
    "tz_short":"CDT",
    "tz_long":"America/Chicago"
},
        "period":3,
        "high": {
        "fahrenheit":"67",
        "celsius":"19"
        },
        "low": {
        "fahrenheit":"41",
        "celsius":"5"
        },
        "conditions":"Clear",
        "icon":"clear",
        "icon_url":"http://icons.wxug.com/i/c/k/clear.gif",
        "skyicon":"",
        "pop":10,
        "qpf_allday": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_day": {
        "in": 0.00,
        "mm": 0
        },
        "qpf_night": {
        "in": 0.00,
        "mm": 0
        },
        "snow_allday": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_day": {
        "in": 0.0,
        "cm": 0.0
        },
        "snow_night": {
        "in": 0.0,
        "cm": 0.0
        },
        "maxwind": {
        "mph": 10,
        "kph": 16,
        "dir": "NNE",
        "degrees": 12
        },
        "avewind": {
        "mph": 8,
        "kph": 13,
        "dir": "NNE",
        "degrees": 12
        },
        "avehumidity": 56,
        "maxhumidity": 0,
        "minhumidity": 0
        }
        ,
        {"date":{

 

Code to grab data/parse it.

 

        Dim WUnderground As New System.Net.WebClient
        Dim URL As String
        URL = "http://api.wunderground.com/api/*****/forecast/q/47715.json"
        Dim result As String = WUnderground.DownloadString(URL)
        Dim matches As MatchCollection = Regex.Matches(result, "epoch[^>]*date")
        For Each match As Match In matches
            MessageBox.Show(match.Value)
        Next

 

But the above only comes up with 1 match, not 5 as it should be. 

 

Using 

 MessageBox.Show(matches.Count.ToString())

Also only shows a 1 so there seems to be something wrong with the RegEx I just can't place it.

 

Thanks!

MCR.jpg?t=1286371579

Most recent sig. I made

Quick Launcher W/ Profiles Topic Movie Database Topic & Website | LiveStreamer Pro Website | YouTube Stand-Alone Playlist Manager: Topic | Weather Desktop Widget: Topic | Flash Memory Game: Topic | Volume Control With Mouse / iTunes Hotkeys: Topic | Weather program: Topic | Paws & Tales radio drama podcast mini-player: Topic | Quick Math Calculations: Topic

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...