zoukankan      html  css  js  c++  java
  • ashx

    请求URL 获取返回数据(JSON格式) 解析JSON格式数据   获取IP地址及城市名称(搜狐)
      HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://pv.sohu.com/cityjson?ie=utf-8");//创建一个URL请求
      HttpWebResponse response = (HttpWebResponse)request.GetResponse();//获取响应,即发送请求 
      Stream responseStream = response.GetResponseStream();
      StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
      //string json = streamReader.ReadToEnd();//获取返回数据(JSON格式)
      string json = streamReader.ReadToEnd().Substring(18);//截取保留18位后的数据
      string JSONS = json.Remove(json.LastIndexOf(";"), 1);//移除最后一个字符
      JavaScriptSerializer js = new JavaScriptSerializer();//序列化
      Dictionary<string, object> dic = js.Deserialize<Dictionary<string, object>>(JSONS);//cip ip地址 cname 地址城市 示例:dic["cip"]
    //连接ACCESS数据库插入数据
      String sqlconn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source = E:/项目/流量报表/XMLS2013/baobiao/data/enterprise.access.config";
      System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection(sqlconn); 
      myConnection.Open();//打开连接
      System.Data.OleDb.OleDbCommand myCommand = new System.Data.OleDb.OleDbCommand("insert into stHour(Ip,UV,FirstDate) values('"+dic["cip"]+"','222','2018/10/15 14:35:15')", myConnection);
      System.Data.OleDb.OleDbDataReader myReader;
      myReader = myCommand.ExecuteReader();
      myConnection.Close();//关闭连接
    //存session
    context.Session["name"] = 123;
    //取session
    string name = context.Session["name"].ToString();
  • 相关阅读:
    B. Xor of 3 题解(思维+构造)
    小 L 与 GCD 题解(数学 hard)
    F. Clear The Matrix 题解(状压dp)
    小顶堆与大顶堆的自定义cmp函数
    字符指针、字符数组
    python中创建dict对象
    中缀表达式转后缀表达式
    vue中keep-alive,include的缓存问题
    vue 冒号 :、@、# 是什么意思? v-bind v-on v-slot v-是指令
    vue 自定义指令 v-
  • 原文地址:https://www.cnblogs.com/zpblogs/p/9790659.html
Copyright © 2011-2022 走看看