I get the error "Cannot convert NULL to a value type" I have seen some other answers on ignoring null values, but I cannot seem to find the property in the Javascriptserializer class. (or any of the other serialization classes offered by .NET)
I have the following function, which uses an httpwebrequest to retrieve a JSON string......
Public Shared Function GetPagerAssignments(Optional ByVal ActiveOnly As Boolean = True) As List(Of PagerAssignment)
Dim mylist As New List(Of PagerAssignment)
Dim myrequest As HttpWebRequest = HttpWebRequest.Create("My URL Here")
myrequest.Proxy = Nothing
myrequest.UserAgent = "PAGER"
myrequest.Method = "GET"
Dim myresponse As HttpWebResponse = myrequest.GetResponse
Dim mystream As System.IO.Stream = (myresponse.GetResponseStream)
Dim streamreader As New System.IO.StreamReader(mystream)
Dim myjsonstring As String = streamreader.ReadToEnd
Try
Dim jss = New JavaScriptSerializer()
mylist = jss.Deserialize(Of List(Of PagerAssignment))(myjsonstring)
Catch ex As Exception
MessageBox.Show("ERROR GETTING PAGER ASSIGNMENTS: " & ex.ToString)
End Try
Return mylist
end function
I have a date value in my JSON string that returns a NULL value, but I need to use this. Here is my JSON..
[
{
""ID"":""283"",
""FirstName"":""JOHN"",
""LastName"":""DOE"",
""AssignedDate"":{""date"":""2019-01-14 09:35:15.573000"",""timezone_type"":3,""timezone"":""America\/Tegucigalpa""},
""RegisteredDate"":{""date"":""2019-01-14 19:46:43.883000"",""timezone_type"":3,""timezone"":""America\/Tegucigalpa""},
""DoctorID"":""54"",
""RoomNumber"":""999"",
""PagerID"":""14"",
""AssigningUser"":""BILLYBOB"",
""Procedure"":""NONE"",
""Notes"":"""",
""ReturnStatus"":0,
""ReturnedDate"":null,
""IsHeld"":0,
""HasOrientation"":0,
""PagerTypeID"":""1"",
""DoctorName"":""PEPPER, DR"",
""PagerName"":""14"",
""PagerTypeName"":""Family""
},
{""ID"":""297"",
""FirstName"":""BUGS"",
""LastName"":""BUNNY"",
""AssignedDate"":{""date"":""2019-01-14 20:29:17.937000"",""timezone_type"":3,""timezone"":""America\/Tegucigalpa""},
""RegisteredDate"":null,
""DoctorID"":""81"",
""RoomNumber"":""45"",
""PagerID"":""20"",
""AssigningUser"":""HOMER S"",
""Procedure"":""54545"",
""Notes"":"""",
""ReturnStatus"":0,
""ReturnedDate"":null,
""IsHeld"":0,
""HasOrientation"":0,
""PagerTypeID"":""1"",
""DoctorName"":""MONROE, MARVIN"",
""PagerName"":""20"",
""PagerTypeName"":""Family""
},
{""ID"":""295"",
""FirstName"":""DAFFY"",
""LastName"":""DUCK"",
""AssignedDate"":{""date"":""2019-01-14 16:11:06.830000"",""timezone_type"":3,""timezone"":""America\/Tegucigalpa""},
""RegisteredDate"":{""date"":""2019-01-14 19:55:50.290000"",""timezone_type"":3,""timezone"":""America\/Tegucigalpa""},
""DoctorID"":""81"",
""RoomNumber"":""876"",
""PagerID"":""24"",
""AssigningUser"":""BART S"",
""Procedure"":""TEST PROCEDURE"",
""Notes"":"""",
""ReturnStatus"":0,
""ReturnedDate"":null,
""IsHeld"":0,
""HasOrientation"":0,
""MRN"":""8734"",
""PagerTypeID"":""1"",
""DoctorName"":""GOODE, PHIL"",
""PagerName"":""24"",
""PagerTypeName"":""Family""
}
]