首页 > Windows开发 > 详细

c# txt中Json数据读取

时间:2020-06-05 15:39:13      阅读:46      评论:0      收藏:0      [点我收藏+]
 string json = Jsonstr(fileName);//Jsonstr函数读取json数据的文本txt                            
 JsonDataT result = JsonConvert.DeserializeObject<JsonDataT>(json);
/// <summary>
/// 转换txt中json
/// </summary>
/// <param name="filePath">文件路径</param>
/// <returns></returns>
public string Jsonstr(String filePath)
{
    string strData = "";
    try
    {
        string line;
        // 创建一个 StreamReader 的实例来读取文件 ,using 语句也能关闭 StreamReader
        using (System.IO.StreamReader sr = new System.IO.StreamReader(filePath))
        {
            // 从文件读取并显示行,直到文件的末尾
            while ((line = sr.ReadLine()) != null)
            {
                //Console.WriteLine(line);
                strData = line;
            }
        }
    }
    catch (Exception e)
    {
        // 向用户显示出错消息
        Console.WriteLine("The file could not be read:");
        Console.WriteLine(e.Message);
    }
    return strData;
}

c# txt中Json数据读取

原文:https://www.cnblogs.com/dreamsails/p/13049638.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!