string requestUri = "http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_NA/GeocodeServer/findAddressCandidates";

 

StringBuilder data = new StringBuilder();

data.AppendFormat("?f={0}", "json");

 

// HttpUtility in System.Web.dll

data.AppendFormat("&Address={0}&Zip={1}", System.Web.HttpUtility.UrlEncode(StreetTextBox.Text),

    System.Web.HttpUtility.UrlEncode(ZoneTextBox.Text));

 

HttpWebRequest request = WebRequest.Create(requestUri + data) as HttpWebRequest;

 

using (HttpWebResponse response = request.GetResponse() as HttpWebResponse)

{

    StreamReader reader = new StreamReader(response.GetResponseStream());

 

    string responseString = reader.ReadToEnd();

 

    // JavaScriptSerializer in System.Web.Extensions.dll

    System.Web.Script.Serialization.JavaScriptSerializer jss =

        new System.Web.Script.Serialization.JavaScriptSerializer();

 

    IDictionary<string, object> results =

        jss.DeserializeObject(responseString) as IDictionary<string, object>;

 

    if (results != null && results.ContainsKey("candidates"))

    {

        IEnumerable<object> candidates = results["candidates"] as IEnumerable<object>;

        foreach (IDictionary<string, object> candidate in candidates)

        {

            string address = candidate["address"] as string;

            IDictionary<string, object> location = candidate["location"] as IDictionary<string, object>;

 

            double x = decimal.ToDouble((decimal)location["x"]);

            double y = decimal.ToDouble((decimal)location["y"]);

            // Do something with coordinate

 

 

            break;

        }

    }

}