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
  1. Home
  2. General Programming
  3. C#
  4. object vs. text stream

object vs. text stream

Scheduled Pinned Locked Moved C#
jsoncsharpquestionjavascriptvisual-studio
2 Posts 1 Posters 0 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.
  • E Offline
    E Offline
    Ed 54
    wrote on last edited by
    #1

    Hello, sorry in advance if this question is too simple for this crowd. I'm new to much of this. I'm building an ASP .NET 2.0 site with C# code behind. It includes calls to the Google Maps API. One of the functions I need is a geocode function. It takes an address and returns lat/long coordinates. I can call it from the client or server with javascript (not preferred), or from the C# code-beside using an HTTP request like this:

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create("URIcodeString");
    HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    Stream resStream = response.GetResponseStream();

    The address and response type are coded into the URIcodeString. I can opt to recieve the response either as an object or as XML. The object looks like this. I can get as far as reading resStream into a String. From there, I'm planning on converting it to XML and parsing it to extract the data elements I need. That will entail some learning on my part, as I don't know XML. That's ok, but it does seem like a brute-force solution. Question: is there a way to receive the JSON object directly and extract the fields I need, to avoid having to parse strings and/or XML? If I can, should I, or is parsing a stream a safer solution when dealing with data sent over the web?

    E 1 Reply Last reply
    0
    • E Ed 54

      Hello, sorry in advance if this question is too simple for this crowd. I'm new to much of this. I'm building an ASP .NET 2.0 site with C# code behind. It includes calls to the Google Maps API. One of the functions I need is a geocode function. It takes an address and returns lat/long coordinates. I can call it from the client or server with javascript (not preferred), or from the C# code-beside using an HTTP request like this:

      HttpWebRequest request = (HttpWebRequest)WebRequest.Create("URIcodeString");
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();
      Stream resStream = response.GetResponseStream();

      The address and response type are coded into the URIcodeString. I can opt to recieve the response either as an object or as XML. The object looks like this. I can get as far as reading resStream into a String. From there, I'm planning on converting it to XML and parsing it to extract the data elements I need. That will entail some learning on my part, as I don't know XML. That's ok, but it does seem like a brute-force solution. Question: is there a way to receive the JSON object directly and extract the fields I need, to avoid having to parse strings and/or XML? If I can, should I, or is parsing a stream a safer solution when dealing with data sent over the web?

      E Offline
      E Offline
      Ed 54
      wrote on last edited by
      #2

      I think I may have answered my own question with a little more web searching. Looks like I should use the Deserialize() method of the XmlSerializer class to convert the XML string into an object type. I'm still a little shaky on OOP, but I can then cast the object into a custom defined type so I can extract the fields I need, right?

      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