Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Deserializing JSON Data in Visual Basic
''' <summary>
''' Deserializes a JSON string to an object of the specified type
''' </summary>
''' <typeparam name="T">Class of object this JSON data will be mapped to</typeparam>
''' <param name="jsonString">String containing the JSON to be deserialized</param>
''' <returns>Mapped object (of type T) representing the JSON data</returns>
Public Shared Function DeserializeJson(Of T)(ByVal jsonString As String) As T
Dim serializer As New DataContractJsonSerializer(GetType(T))
Dim memStream As New MemoryStream(Encoding.UTF8.GetBytes(jsonString))
Dim obj As T = DirectCast(serializer.ReadObject(memStream), T)
Return obj
End Function
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment