zoukankan      html  css  js  c++  java
  • .net从网络接口地址获取json,然后解析成对象(二)

    整理代码,这是第二种方法来读取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 }
     
  • 相关阅读:
    HTML 5 全局属性
    微软build 2015
    写个程序登陆58同城
    工厂方法
    简单工厂
    System.Data.SQLite兼容32位和64位问题
    利用Socket实现的两个程序的通信
    最近的工作总结
    Canvas路径、描边、填充
    HTML5阴影与渐变
  • 原文地址:https://www.cnblogs.com/Lvkang/p/9395320.html
Copyright © 2011-2022 走看看