/// <summary> /// 网页返回port /// </summary> /// <param name="WebAddress">待处理网页地址</param> /// <returns></returns> public int ReturnPort() { string WebAddress = webAddress; LogicCommon logicCommon = new LogicCommon(); DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(WebJsonModel)); using (MemoryStream memoryStream = new MemoryStream(Encoding.Unicode.GetBytes(logicCommon.JsonToString(WebAddress)))) { WebJsonModel webJsonModel = ser1.ReadObject(memoryStream) as WebJsonModel; return(webJsonModel.port); } }
/// <summary> /// Json转换String获取端口 /// </summary> /// <param name="WebAddress">待处理网页地址</param> /// <returns></returns> public int JsonToStringPort(string WebAddress) { WebClient MyWebClient = new WebClient { Credentials = CredentialCache.DefaultCredentials }; string a = MyWebClient.DownloadString(WebAddress); DataContractJsonSerializer ser1 = new DataContractJsonSerializer(typeof(WebJsonModel)); using (MemoryStream ms = new MemoryStream(Encoding.Unicode.GetBytes(a))) { WebJsonModel foo1 = ser1.ReadObject(ms) as WebJsonModel; return(foo1.port); } }