Csharp: WebBrowser read baidumap, csharpbaidumap
Setpoint.html:
<! DOCTYPE html>
Using System; using System. collections. generic; using System. linq; using System. text; using System. collections; using System. web; using System. web. script. serialization; // reference System. web. extensions using System. data; using System. IO; using System. runtime. serialization; using System. runtime. serialization. json; using System. runtime. serialization. formatters;
/// <Summary> ///// </summary> public class JsonHelper {// public string singleInfo = string for the corresponding JSON singleInfo Member. empty; protected string _ error = string. empty; protected bool _ success = true; protected long _ totalCount = 0; protected System. collections. arrayList arrData = new ArrayList (); protected System. collections. arrayList arrDataItem = new ArrayList (); public JsonHelper () {// TODO: Add a structure here Create Function logic //} // The success member public bool success {get {return _ success;} set {// clear error if (success) if it is set to true) _ error = string. empty; _ success = value ;}/// public string error {get {return _ error ;}set {// If error is set, set success to false if (value! = "") _ Success = false; _ error = value ;}} public long totlalCount {get {return _ totalCount ;}set {_ totalCount = value ;}// reset, every time a json object is generated, the public void Reset () {_ success = true; _ error = string. empty; singleInfo = string. empty; arrData. clear (); arrDataItem. clear ();} public void AddItem (string name, string value) {arrData. add ("/" + name + "/:" + "/" + value + "/");} public void I TemOk () {arrData. add ("<BR>"); // total number of returned records totlalCount ++;} // serialize the JSON object to obtain the returned JSON code public override string ToString () {StringBuilder sb = new StringBuilder (); sb. append ("{"); sb. append ("/totalCount/:/" + _ totalCount. toString () + "/,"); sb. append ("/success/:" + _ success. toString (). toLower () + "/,"); sb. append ("/error/:/" + _ error. replace ("/", "//") + "/,"); sb. append ("/data/:/["); int index = 0; sb. Append ("{"); if (arrData. count <= 0) {sb. append ("}") ;}else {foreach (string val in arrData) {index ++; if (val! = "<BR>") {sb. append (val + ",");} else {sb = sb. replace (",", "", sb. length-1, 1); sb. append ("},"); if (index <arrData. count) {sb. append ("{") ;}} sb = sb. replace (",", "", sb. length-1, 1); sb. append ("]");} sb. append ("}"); return sb. toString ();} public string ToSingleString () {StringBuilder sb = new StringBuilder (); sb. append ("{"); sb. append ("success:" + _ success. toString (). toLower () + ","); Sb. append ("data:"); int index = 0; sb. append ("{"); if (arrData. count <= 0) {sb. append ("}") ;}else {foreach (string val in arrData) {index ++; if (val! = "<BR>") {sb. append (val + ",");} else {sb = sb. replace (",", "", sb. length-1, 1); sb. append ("},"); if (index <arrData. count) {sb. append ("{") ;}} sb = sb. replace (",", "", sb. length-1, 1); sb. append ("");} sb. append ("}"); return sb. toString ();} public static string ObjectToJSON (object obj) {JavaScriptSerializer jss = new JavaScriptSerializer (); try {return jss. serialize (obj);} catch (Exception ex) {throw new Exception ("JSONHelper. objectToJSON (): "+ ex. message) ;}} public static List <Dictionary <string, object> DataTableToList (DataTable dt) {List <Dictionary <string, object> list = new List <Dictionary <string, object >>> (); foreach (DataRow dr in dt. rows) {Dictionary <string, object> dic = new Dictionary <string, object> (); foreach (DataColumn dc in dt. columns) {dic. add (dc. columnName, dr [dc. columnName]);} list. add (dic) ;}return list ;} /// <summary> ///// </summary> /// <param name = "ds"> </param> /// <returns> </returns> public static Dictionary <string, list <Dictionary <string, object >>> DataSetToDic (DataSet ds) {Dictionary <string, List <Dictionary <string, object >>> result = new Dictionary <string, list <Dictionary <string, object >>> (); foreach (DataTable dt in ds. tables) result. add (dt. tableName, DataTableToList (dt); return result ;} /// <summary> ///// </summary> /// <param name = "dt"> </param> /// <returns> </returns> public static string DataTableToJSON (DataTable dt) {return ObjectToJSON (DataTableToList (dt ));} /// <summary> ///// </summary> /// <typeparam name = "T"> </typeparam> /// <param name = "jsonText "> </param> // <returns> </returns> public static T JSONToObject <T> (string jsonText) {JavaScriptSerializer jss = new JavaScriptSerializer (); try {return jss. deserialize <T> (jsonText);} catch (Exception ex) {throw new Exception ("JSONHelper. JSONToObject (): "+ ex. message );}} /// <summary> ///// </summary> /// <param name = "jsonText"> </param> /// <returns> </returns> public static Dictionary <string, list <Dictionary <string, object >>> TablesDataFromJSON (string jsonText) {return JSONToObject <Dictionary <string, List <Dictionary <string, object >>> (jsonText );} /// <summary> ///// </summary> /// <param name = "jsonText"> </param> /// <returns> </returns> public static Dictionary <string, object> DataRowFromJSON (string jsonText) {return JSONToObject <Dictionary <string, object> (jsonText);} public static string ToJsJson (object item) // The object whose parameters need to be replaced with JSON {DataContractJsonSerializer serializer = new DataContractJsonSerializer (item. getType (); using (MemoryStream MS = new MemoryStream () {serializer. writeObject (MS, item); StringBuilder sb = new StringBuilder (); sb. append (Encoding. UTF8.GetString (ms. toArray (); return sb. toString () ;}/// deserialization // T specifies the object to be serialized. jsonString is the JSON string variable public static T FromJsonTo <T> (string jsonString) {DataContractJsonSerializer ser = new DataContractJsonSerializer (typeof (T); using (MemoryStream MS = new MemoryStream (Encoding. UTF8.GetBytes (jsonString) {T jsonObject = (T) ser. readObject (MS); return jsonObject ;}}}
/// <Summary> /// provides Http-related methods. /// </Summary> public class HttpUtils {/// <summary> /// execute the http get request. /// </Summary> /// <param name = "url"> request address </param> /// <param name = "parameters"> request parameter </param >/// <returns> HTTP Response </returns> public static string DoGet (string url, IDictionary <string, string> parameters) {if (parameters! = Null & parameters. Count> 0) {if (url. Contains ("? ") {Url = url +" & "+ BuildPostData (parameters);} else {url = url + "? "+ BuildPostData (parameters) ;}} HttpWebRequest req = (HttpWebRequest) WebRequest. create (url); req. servicePoint. expect100Continue = false; req. method = "GET"; req. keepAlive = true; req. userAgent = "Test"; req. contentType = "application/x-www-form-urlencoded; charset = UTF-8"; HttpWebResponse rsp = null; try {rsp = (HttpWebResponse) req. getResponse ();} catch (WebException webEx) {if (webEx. status = WebExceptionStatus. Timeout) {rsp = null ;}} if (rsp! = Null) {if (rsp. CharacterSet! = Null) {Encoding encoding = Encoding. getEncoding (rsp. characterSet); return GetResponseAsString (rsp, encoding);} else {return string. empty ;}} else {return string. empty ;}/// <summary> // convert the response to text. /// </Summary> /// <param name = "rsp"> response Stream object </param> /// <param name = "encoding"> encoding method </ param> // <returns> response text </returns> private static string GetResponseAsString (HttpWebResponse rsp, encoding encoding) {StringBuilder result = new StringBuilder (); Stream stream = null; StreamReader reader = null; try {// read the HTTP Response stream = rsp as a response Stream. getResponseStream (); reader = new StreamReader (stream, encoding ); // Read a string of no more than 256 characters and write the string char [] buffer = new char [256]; int readBytes = 0; while (readBytes = reader. read (buffer, 0, buffer. length)> 0) {result. append (buffer, 0, readBytes) ;}} catch (WebException webEx) {if (webEx. status = WebExceptionStatus. timeout) {result = new StringBuilder () ;}} finally {// release the resource if (reader! = Null) reader. Close (); if (stream! = Null) stream. Close (); if (rsp! = Null) rsp. Close () ;}return result. ToString () ;}/// <summary> /// assemble common text request parameters. /// </Summary> /// <param name = "parameters"> request parameter dictionary in Key-Value format. </Param> // <returns> URL-encoded request data. </Returns> private static string BuildPostData (IDictionary <string, string> parameters) {StringBuilder postData = new StringBuilder (); bool hasParam = false; IEnumerator <KeyValuePair <string, string> dem = parameters. getEnumerator (); while (dem. moveNext () {string name = dem. current. key; string value = dem. current. value; // ignore the parameter if (! String. IsNullOrEmpty (name )&&! String. isNullOrEmpty (value) {if (hasParam) {postData. append ("&");} postData. append (name); postData. append ("="); postData. append (Uri. escapeDataString (value); hasParam = true ;}} return postData. toString ();}/* GoBack (): backward GoForward (): Forward Refresh (): Refresh Stop (): Stop GoHome (): common attributes of the WebBrowser control: document: Get the currently viewed Document DocumentTitle: Get the currently viewed webpage title StatusText: Get the text Url of the Current Status Bar: Get the Uri ReadyState of the currently browsed Url: obtain common events of the browser control: DocumentTitleChanged, CanGoBackChanged, CanGoForwardChanged, DocumentTitleChanged, ProgressChanged, progressChanged * //// <summary> /// obtain the element by Name /// </summary> /// <param name = "wb"> </param> // /<param name = "Name"> </param> // <returns> </returns> public HtmlElement GetElement_Name (WebBrowser wb, string Name) {HtmlElement e = wb. document. all [Name]; return e ;} /// <summary> /// obtain the element by Id /// </summary> /// <param name = "wb"> </param> /// <param name = "id"> </param> // <returns> </returns> public HtmlElement GetElement_Id (WebBrowser wb, string id) {HtmlElement e = wb. document. getElementById (id); return e ;} /// <summary> /// obtain the element based on the Index /// </summary> /// <param name = "wb"> </param> /// <param name = "index"> </param> // <returns> </returns> public HtmlElement GetElement_Index (WebBrowser wb, int index) {HtmlElement e = wb. document. all [index]; return e ;}/// <summary> /// obtain the form name, return form /// </summary> /// <param name = "wb"> </param> /// <param name = "form_name"> </param>/ // <returns> </returns> public HtmlElement GetElement_Form (WebBrowser wb, string form_name) {HtmlElement e = wb. document. forms [form_name]; return e ;} /// <summary> /// set the value of the element value attribute /// </summary> /// <param name = "e"> </param> /// <param name = "value"> </param> public void Write_value (HtmlElement e, string value) {e. setAttribute ("value", value) ;}/// <summary> // Method for executing elements, such as click and submit (Form name required) and so on /// </summary> /// <param name = "e"> </param> /// <param name = "s"> </param> public void btn_click (HtmlElement e, string s) {e. invokeMember (s );}}
Workflow:
Https://jsplumbtoolkit.com/demos/toolkit/flowchart-builder/index.html