-1

I have this JSON string :

{
    "Store": [{
        "StoreID": "8643",
        "IsDeliveryStore": true,
        "MinDistance": 0.6,
        "MaxDistance": 0.6,
        "Phone": "352-505-5557",
        "AddressDescription": "3581 sw archer rd\nGainesville, FL 32608",
        "HolidaysDescription": "",
        "HoursDescription": "Mo-Fr 9:30am-4:00am\nSa-Su 10:00am-4:00am",
        "ServiceHoursDescription": {
            "Carryout": "Mo-Fr 9:30am-4:00am\nSa-Su 10:00am-4:00am",
            "Delivery": "Mo-Fr 9:30am-4:00am\nSa-Su 10:00am-4:00am"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": true,
        "IsNEONow": false,
        "IsSpanish": true,
        "LocationInfo": null,
        "LanguageLocationInfo": {
            "es": null
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }, {
        "StoreID": "3214",
        "IsDeliveryStore": false,
        "MinDistance": 2.1,
        "MaxDistance": 2.1,
        "Phone": "352-377-4992",
        "AddressDescription": "3309 W University Ave\nGainesville, FL 32607\nIn Publix Plazza.",
        "HolidaysDescription": "",
        "HoursDescription": "Su-Th 10:00am-3:00am\nFr-Sa 10:00am-4:00am",
        "ServiceHoursDescription": {
            "Carryout": "Su-Th 10:00am-3:00am\nFr-Sa 10:00am-4:00am",
            "Delivery": "Su-Th 10:00am-3:00am\nFr-Sa 10:00am-4:00am"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": true,
        "IsNEONow": false,
        "IsSpanish": false,
        "LocationInfo": "In Publix Plazza.",
        "LanguageLocationInfo": {
            "es": "In Publix Plazza."
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }, {
        "StoreID": "3172",
        "IsDeliveryStore": false,
        "MinDistance": 2.7,
        "MaxDistance": 2.7,
        "Phone": "352-373-8888",
        "AddressDescription": "5750 SW 75th Ct #40\nGainesville, FL 32608\nIn Park Lane Plaza  .",
        "HolidaysDescription": "",
        "HoursDescription": "Su-Th 10:00am-1:00am\nFr-Sa 10:00am-2:00am",
        "ServiceHoursDescription": {
            "Carryout": "Su-Th 10:00am-1:00am\nFr-Sa 10:00am-2:00am",
            "Delivery": "Su-Th 10:00am-1:00am\nFr-Sa 10:00am-2:00am"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": true,
        "IsNEONow": false,
        "IsSpanish": true,
        "LocationInfo": "In Park Lane Plaza  .",
        "LanguageLocationInfo": {
            "es": "In Park Lane Plaza  ."
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }, {
        "StoreID": "5150",
        "IsDeliveryStore": false,
        "MinDistance": 2.9,
        "MaxDistance": 2.9,
        "Phone": "352-373-2337",
        "AddressDescription": "2106 Sw 13th St\nGainesville, FL 32608\nIn Domino's Plaza.",
        "HolidaysDescription": "",
        "HoursDescription": "Mo-Fr 9:30am-4:00am\nSa-Su 10:00am-4:00am",
        "ServiceHoursDescription": {
            "Carryout": "Mo-Fr 9:30am-4:00am\nSa-Su 10:00am-4:00am",
            "Delivery": "Mo-Fr 9:30am-4:00am\nSa-Su 10:00am-4:00am"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": false,
        "IsNEONow": false,
        "IsSpanish": false,
        "SubstitutionStore": "3213",
        "LocationInfo": "In Domino's Plaza.",
        "LanguageLocationInfo": {
            "es": "In Domino's Plaza."
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }, {
        "StoreID": "3246",
        "IsDeliveryStore": false,
        "MinDistance": 4.5,
        "MaxDistance": 4.5,
        "Phone": "352-692-2222",
        "AddressDescription": "4620 NW 39th Ave\nGainesville, FL\nLocated at Magnolia Park.",
        "HolidaysDescription": "",
        "HoursDescription": "Su-Th 10:00am-12:00am\nFr-Sa 10:00am-1:30am",
        "ServiceHoursDescription": {
            "Carryout": "Su-Th 10:00am-12:00am\nFr-Sa 10:00am-1:30am",
            "Delivery": "Su-Th 10:00am-12:00am\nFr-Sa 10:00am-1:30am"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": true,
        "IsNEONow": false,
        "IsSpanish": true,
        "LocationInfo": "Located at Magnolia Park.",
        "LanguageLocationInfo": {
            "es": "Located at Magnolia Park."
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }, {
        "StoreID": "3261",
        "IsDeliveryStore": false,
        "MinDistance": 4.7,
        "MaxDistance": 4.7,
        "Phone": "352-505-6845",
        "AddressDescription": "3000 NW 83rd Street\nGainesville, FL 32606\nLocated at the Food Court of Santa Fe College (Bldg R).",
        "HolidaysDescription": "",
        "HoursDescription": "Mo-Fr 8:30am-5:00pm\nSa-Su Closed",
        "ServiceHoursDescription": {
            "Carryout": "Mo-Fr 8:30am-5:00pm\nSa-Su Closed",
            "Delivery": "Mo-Fr 8:30am-5:00pm\nSa-Su Closed"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": true,
        "IsNEONow": false,
        "IsSpanish": true,
        "LocationInfo": "Located at the Food Court of Santa Fe College (Bldg R).",
        "LanguageLocationInfo": {
            "es": "Located at the Food Court of Santa Fe College (Bldg R)."
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }, {
        "StoreID": "3213",
        "IsDeliveryStore": false,
        "MinDistance": 4.7,
        "MaxDistance": 4.7,
        "Phone": "352-373-5555",
        "AddressDescription": "25 Nw 16th Ave\nGainesville, FL 32601\nOn the north corner of Main Street and NW 16th avenue.",
        "HolidaysDescription": "",
        "HoursDescription": "Su-Th 10:00am-3:00am\nFr-Sa 10:00am-4:00am",
        "ServiceHoursDescription": {
            "Carryout": "Su-Th 10:00am-3:00am\nFr-Sa 10:00am-4:00am",
            "Delivery": "Su-Th 10:00am-3:00am\nFr-Sa 10:00am-4:00am"
        },
        "IsOnlineCapable": true,
        "IsOnlineNow": true,
        "IsNEONow": false,
        "IsSpanish": false,
        "LocationInfo": "On the north corner of Main Street and NW 16th avenue.",
        "LanguageLocationInfo": {
            "es": "On the north corner of Main Street and NW 16th avenue."
        },
        "AllowDeliveryOrders": true,
        "AllowCarryoutOrders": true,
        "IsOpen": true,
        "ServiceIsOpen": {
            "Carryout": true,
            "Delivery": true
        }
    }]
}

I'm trying to parse this, this is my code :

Dim StoreWrapper = JsonConvert.DeserializeObject(Of StoreWrapper)(html)
Dim AllStores = StoreWrapper.Stores
Results.Text = AllStores(1).StoreID.ToString

Public Class StoreWrapper
    Public Property Store As List(Of Store)
End Class
Public Class Store
Public Property StoreID As String
Public Property IsDeliveryStore As Boolean
Public Property MinDistance As Double
Public Property MaxDistance As Double
Public Property Phone As String
Public Property AddressDescription As String
Public Property HolidaysDescription As String
Public Property HoursDescription As String
'Public Property ServiceHoursDescription As String
Public Property IsOnlineCapable As Boolean
Public Property IsOnlineNow As Boolean
Public Property IsNEONow As Boolean
Public Property IsSpanish As Boolean
Public Property LocationInfo As String
'Public Property LanguageLocationInfo As String
Public Property AllowDeliveryOrders As Boolean
Public Property AllowCarryoutOrders As Boolean
Public Property IsOpen As Boolean
'Public Property ServiceIsOpen As String
End Class

The error I'm getting is :

An unhandled exception of type 'System.NullReferenceException' occurred in LocationFinder.exe

Additional information: Object reference not set to an instance of an object.

  • Please read [ask] and take the [tour] we need to know which line it happens at. Also take the time to learn how to format the code so it looks like code – Ňɏssa Pøngjǣrdenlarp Dec 27 '16 at 18:14
  • Your class is not quite correct. Not evenrything is string, there are some Booleans (`true` is a bool, `"true"` would be string) and doubles in there; it also looks like you are missing some Types: `ServiceHoursDescription`, `LanguageLocationInfo` and `ServiceIsOpen ` are their own types – Ňɏssa Pøngjǣrdenlarp Dec 27 '16 at 18:20
  • 2
    Possible duplicate of [What is a NullReferenceException, and how do I fix it?](http://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it) – Jeff Mercado Dec 27 '16 at 18:23
  • 1
    Note: the final result is an NRE but *that* is a result of the Store class being incorrect, so `StoreWrapper` will usually be Nothing. The code doesnt check if it deserialized but there is not much on the canonical that will help the OP to actually resolve the underlying problem. Unfortunately, s/he just dumped their problem like so much dirty laundry and fled the scene; so if it closed as a dupe they cant really blame anyone but themselves. – Ňɏssa Pøngjǣrdenlarp Dec 27 '16 at 18:54
  • Thank you. The line where the error occurs is `Results.Text = AllStores(1).StoreID.ToString` I did change the types to match, I left out the ones that need to be types because I don't really need those. Am I correct that I don't have to read every token from the JSON? – Graham Ballard Dec 27 '16 at 22:11

1 Answers1

0

The needed change was Public Property Store As List(Of Store)

Thanks!