Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. Visual Basic
  4. JSON in a console application

JSON in a console application

Scheduled Pinned Locked Moved Visual Basic
c++jsonhelpquestion
1 Posts 1 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    oakleaf
    wrote on last edited by
    #1

    I have a windows form application (VB) that can serialize and deserialize some JSON for me, however, I cannot seem to serialize and deserialize JSON in a console application (the ultimate goal here). I am starting to get the feeling that I am attempting to do something that is not even possible, even though I have seen a couple examples of this being done in C++.

    Dim url As String = ""
    Dim myHttpWebRequest As HttpWebRequest = CType(WebRequest.Create(url), HttpWebRequest)
    myHttpWebRequest.Credentials = New NetworkCredential("user", "pass")
    myHttpWebRequest.PreAuthenticate = True
    Dim myHttpWebResponse As HttpWebResponse = CType(myHttpWebRequest.GetResponse(), HttpWebResponse)
    Dim receiveStream As Stream = myHttpWebResponse.GetResponseStream()
    Dim reader4 As New StreamReader(receiveStream)
    Dim response3FromServer As String = reader4.ReadToEnd()
    Console.WriteLine("responseFromServer: " & response3FromServer)

    The above will retrieve the JSON and display it, no problem.

    Dim deserializedOrder2 As New CardItems()
    Dim ms2 As New MemoryStream(Encoding.UTF8.GetBytes(response3FromServer))
    Dim ser2 As New DataContractJsonSerializer(deserializedOrder2.GetType())
    deserializedOrder2 = TryCast(ser2.ReadObject(ms2), CardItems)
    CardID = deserializedOrder2.CardID
    Console.WriteLine(CardID)

    Now obviously I have CardItems all set up with members, CardID being one of them, but I can't seem to get the value. Is there a problem with the above?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups