0

I have searched for the answer to this for a few hours with no successful code.

How can I convert a JSON string to an array OR a JSON string to XML in VB.NET? I know how to do this in C#, as I have read dozens of articles on it, however, I am unable to figure out how to achieve the same result in VB.NET.

I'm using the System.Web.Script namespace via System.Web.Extensions.dll (from Microsoft).

I'm willing to use an additional DLL file if needed.

4
  • 1
    Show us your C# code; almost all C# can be trivially converted to VB.Net. Commented Jul 17, 2011 at 4:19
  • This is the code I have been using in C# - procbits.com/2011/04/21/… Commented Jul 17, 2011 at 4:25
  • What problem are you having in VB.Net? Commented Jul 17, 2011 at 4:26
  • I don't know the correct VB.Net syntax of var dict = jss.Deserialize<Dictionary<string,dynamic>>(jsonText); Commented Jul 17, 2011 at 4:36

1 Answer 1

3
Dim dict = jss.Deserialize(Of Dictionary(Of String, Object))(jsonText)

Generic types in VB.Net

Sign up to request clarification or add additional context in comments.

4 Comments

Visual Studio puts a line under "Dynamic" and says "Type expected." Any ideas?
VB.Net doesn't have Dynamic; you need to use Object instead. Option Strict Off will make it easier to work with.
Almost there, now it says this error: Type 'System.Collections.Generic.Dictionary2[[System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089],[System.Object, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' is not supported for deserialization of an array.
Figured it out with the help of @SLaks. Here is what I ended up using: Dim jss = New JavaScriptSerializer() then Dim table = jss.Deserialize(Of Object)(str) and finally table(0)("key name")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.