0 Replies - 419 Views - Last Post: 12 April 2013 - 07:05 AM Rate Topic: -----

#1 StealthRT  Icon User is offline

  • D.I.C Head

Reputation: 1
  • View blog
  • Posts: 55
  • Joined: 29-September 08

JSON.net getting elements from response

Posted 12 April 2013 - 07:05 AM

Hey all i have the following **VB.net** code to find elements within a JSON response:
    Dim url As String = "http://api.rovicorp.com/TVlistings/v9/listings/gridschedule/430008/info?locale=en-US&duration=240&includechannelimages=1&format=json&apikey=" & api_TV
    Dim request As HttpWebRequest
    Dim response As HttpWebResponse = Nothing
    Dim reader As StreamReader

    request = DirectCast(WebRequest.Create(url), HttpWebRequest)
    response = DirectCast(request.GetResponse(), HttpWebResponse)
    reader = New StreamReader(response.GetResponseStream())

    Dim o As JObject = JObject.Parse(reader.ReadToEnd)
    Dim Channel As String = DirectCast(o("GridScheduleResult")("GridChannels")(0)("Channel").ToString(), String)
    Dim CallLetters As String = DirectCast(o("GridScheduleResult")("GridChannels")(0)("CallLetters").ToString(), String)
    Dim SourceLongName As String = DirectCast(o("GridScheduleResult")("GridChannels")(0)("SourceLongName").ToString(), String)

    Dim showTitle As String = DirectCast(o("GridScheduleResult")("GridChannels")(0)("Airings")("Title").ToString(), String)


Problem is this like
    Dim showTitle As String = DirectCast(o("GridScheduleResult")("GridChannels")(0)("Title").ToString(), String)


The JSON response looks like this:
    {
    "{
    "GridScheduleResult": {
        "Locale": "en-US",
        "ServiceId": 430008,
        "Name": "City here - Comcast",
        "StartDate": "2013-04-11T19:54:12.990887Z",
        "Duration": 240,
        "RequestId": "b8ebd84c-6718-40dd-8a3b-430dfb7dc9ac",
        "TimeStamp": "2013-04-11T19:54:12.99Z",
        "Status": "PNE",
        "Errors": [],
        "EndTimestamp": "2013-04-11T19:54:13.287Z",
        "Build": "9.13.3",
        "TimeZones": [{
            "StartDateTime": "2013-03-10T07:00:00Z",
            "EndDateTime": "2013-11-03T06:00:00Z",
            "Offset": -240
        }],
        "GridChannels": [{
            "ServiceId": 890138,
            "SourceId": 10511,
            "Order": 10001,
            "Channel": "1",
            "CallLetters": "VOD",
            "DisplayName": "VOD",
            "SourceLongName": "Video On Demand",
            "Type": "24-Hours",
            "SourceType": "Basic",
            "ParentNetworkId": 0,
            "IconAvailable": false,
            "IsChannelOverride": false,
            "SourceAttributes": "8",
            "ChannelSchedules": [],
            "SourceAttributeTypes": "",
            "Airings": [{
                "ProgramId": "3466024",
                "Title": "Video on Demand",
                "AiringTime": "2013-04-11T05:00:00Z",
                "Duration": 1440,
                "Color": "Unknown",
                "AiringType": "Unknown",
                "CC": false,
                "LetterBox": false,
                "Stereo": false,
                "HD": false,
                "SAP": false,
                "TVRating": "None",
                "Dolby": false,
                "DSS": false,
                "HDLevel": "HD Level Unknown",
                "DVS": false,
                "Category": "Other",
                "Sports": false
            }],
            "ChannelImages": []
        }, {
            "ServiceId": 890138,
            "SourceId": 1280,
            "Order": 20002,
            "Channel": "2",
            "CallLetters": "WGNAMER",
            "DisplayName": "WGNAMER",
            "SourceLongName": "WGN America",
            "Type": "24-Hours",
            "SourceType": "Basic",
            "ParentNetworkId": 0,
            "IconAvailable": false,
            "IsChannelOverride": false,
            "SourceAttributes": "0",
            "ChannelSchedules": [],
            "SourceAttributeTypes": "",
            "Airings": [{
                "ProgramId": "1070299",
                "SeriesId": "1028666",
                "Title": "Walker, Texas Ranger",
                "EpisodeTitle": "The Juggernaut",
                "AiringTime": "2013-04-11T19:00:00Z",
                "Duration": 60,
                "Color": "Color",
                "AiringType": "Unknown",
                "CC": true,
                "LetterBox": false,
                "Stereo": true,
                "HD": false,
                "SAP": false,
                "TVRating": "TV-14@V",
                "Dolby": false,
                "DSS": false,
                "HDLevel": "HD Level Unknown",
                "DVS": false,
                "Category": "Other",
                "Subcategory": "crime drama",
                "Sports": false
            }, {
                "ProgramId": "879248",
           ETC ETC ETC....


I've tried:
     Dim showTitle As String = DirectCast(o("GridScheduleResult")("GridChannels")("Airings")(0)("Title").ToString(), String)


But that also produces an error.

I also need to know how to loop through all 200+ CallLetters, titles, etc...

Any help would be great!

Is This A Good Question/Topic? 0
  • +

Page 1 of 1