整理代码,这是第二种方法来读取json,然后反序列化成对象的,代码如下:
1 public static Order GetOrderInfo(string _tid, string _orderNo) 2 { 3 try 4 { 5 StringBuilder serviceUrl = new StringBuilder(); 6 serviceUrl.Append("http://10.10.10.10/queryOrderTwo?"); 7 serviceUrl.AppendFormat("tid={0}&tname=&email=&employeeno=&corpcode=&serviceCode=&pageNum=&pageSize=&productType=&dateFrom=&dateTo=&dateType=&sono={1}", _tid, _orderNo); 8 string _result = ExcuteGet(serviceUrl.ToString()); 9 return JsonConvert.DeserializeObject<Order>(_result); 10 } 11 catch (Exception e) 12 { 13 AddLog(_tid, "获取订单List异常:" + e.Message.ToSql(), "GetOrderList"); 14 return null; 15 } 16 }
ExcuteGet的方法和第一种时不一样,
1 public static string ExcuteGet(string url) 2 { 3 var request = (HttpWebRequest)WebRequest.Create(url); 4 var response = (HttpWebResponse)request.GetResponse(); 5 return new StreamReader(response.GetResponseStream()).ReadToEnd(); 6 }