C# Newtonsoft.Json 读取文件,返回json字符串
2021-02-02 21:17
标签:返回 format serve ring code convert public tst adt 第一种方法: 第二种方法: 第三种方法:直接返回json文件,设置返回类型ContentType为“application/json": C# Newtonsoft.Json 读取文件,返回json字符串 标签:返回 format serve ring code convert public tst adt 原文地址:https://www.cnblogs.com/AlexanderZhao/p/11529950.html public object getData2()
{
string content;
using (StreamReader sr = new StreamReader(Server.MapPath("/Content/test.json")))
{
content = sr.ReadToEnd();
}
JsonSerializerSettings jSetting = new JsonSerializerSettings
{
NullValueHandling = NullValueHandling.Ignore,
DateFormatString = "yyyy-MM-dd HH:m:ss"
};
var jsonObject = JsonConvert.DeserializeObject
public string getData()
{
string content;
using (StreamReader sr = new StreamReader(Server.MapPath("/Content/test.json")))
{
content = sr.ReadToEnd().Replace("\r", string.Empty).Replace("\n", string.Empty).Replace("\t", string.Empty);
}
return content;
}
public FilePathResult getData3()
{
return new FilePathResult("~/Content/test.json", "application/json");
}
上一篇:【c#基础】表达式树
下一篇:【C#基础】Linq提供程序
文章标题:C# Newtonsoft.Json 读取文件,返回json字符串
文章链接:http://soscw.com/index.php/essay/50120.html