• c#读取txt文件


    using LitJson;

     private void btnRead_Click(object sender, EventArgs e)
            {
                string path = @"D:/test.json";//读取文件txt  
                using (FileStream fs = new FileStream(path, FileMode.Open))
                {
                     using (StreamReader sr = new StreamReader(fs,UnicodeEncoding.GetEncoding("GB2312")))
                     {
                          while (!sr.EndOfStream) 
                          { 
                               string sLine = sr.ReadToEnd(); 
                               if(sLine.Length>0)
                               {
                                   JsonData jd = JsonMapper.ToObject(sLine);
                                   this.textBox1.Text = (String)jd["name"];


                                   //long id = (long)jd["id"];
                                   JsonData jdItems = jd["items"];
                                   //int itemCnt = jdItems.Count;
                                   //// 数组 items 中项的数量
                                   foreach (JsonData item in jdItems)
                                   // 遍历数组 items           
                                   {
                                       int itemID = (int)item["itemid"];
                                       String itemName = (String)item["itemname"];
                                       this.textBox1.Text += itemID.ToString() + " " + itemName.ToString();
                                   }

                                   ////*** 将JsonData转换为JSON字符串 ***************************         

                                   //String str2 = jd.ToJson();
                               }
                          } 
                     }
                }
            }

  • 相关阅读:
    SpringCloud06Config远程配置
    SpringCloud05Zuul网关
    SpringCloud02Ribbon负载均衡
    Springboot06Dubbo+Zookeeper
    SpringCloud03Feign负载均衡
    @SpringbootApllication主启动类注解分析
    SpringCloud04Hystrix熔断机制
    SpringCloud01Eureka注册中心
    Redis笔记
    C++while循环特殊用法
  • 原文地址:https://www.cnblogs.com/jason819/p/3236709.html
Copyright © 2020-2023  润新知