1

Is there any possible way to convert direct url to json into xml as text into one textbox?

Example:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim Json1 as string = "http://pastebin.com/raw.php?i=p3uBzBtm"
    Dim jss = New JsonSerializer()
    Dim response2 = jss.Deserialize(Of Object)(Json1)
    textbox1.text = response2
End Sub

Sorry for this bad example, I'm newbie in this language.

3
  • What is the expected output (Textbox1's text)? Commented Oct 30, 2015 at 14:03
  • Where I want to be the converted xml result. Commented Oct 30, 2015 at 14:07
  • Got it. Check out the answer. Commented Oct 30, 2015 at 14:10

1 Answer 1

4

Use this code:

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim Json1 As String = New WebClient().DownloadString("http://pastebin.com/raw.php?i=p3uBzBtm")
    Dim str = JsonConvert.DeserializeXmlNode(Json1)
    TextBox1.Text = str.OuterXml
End Sub

For multiple nodes you will want something like this:

Dim Json1 As String = "{ 'root': " & New WebClient().DownloadString("http://pastebin.com/raw.php?i=ugZrw4d6") & " }"
Dim doc As XmlDocument = JsonConvert.DeserializeXmlNode(Json1)
Dim result As String = doc.ChildNodes(0).InnerXml
TextBox1.Text = result
Sign up to request clarification or add additional context in comments.

4 Comments

It worked, thank you so much! But I see if I want to change the Download String url with another that have multiple lines and nodes it give me error. Can you optimize for this link? pastebin.com/raw.php?i=ugZrw4d6
Since valid xml has only one root node, you have to enclose your JSON in a single object. See updated answer.
This is exactly what I wanted. Thank you so much for your amazing helps!
@qckmini6 Consider accepting this answer. It will help others know that it is a useful solution :)

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.