Skip to content

Instantly share code, notes, and snippets.

@christherama
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save christherama/945ad0e9d863273e0f7b to your computer and use it in GitHub Desktop.
Save christherama/945ad0e9d863273e0f7b to your computer and use it in GitHub Desktop.
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