Last active
August 29, 2015 14:20
-
-
Save christherama/945ad0e9d863273e0f7b to your computer and use it in GitHub Desktop.
Deserializing JSON Data in Visual Basic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' <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