object vs. text stream
-
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?
-
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?
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?