using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
///
/// 读取JSON文件
///
/// JSON文件中的key值
/// JSON文件中的value值
public static string Readjson(string key)
{
string jsonfile = "D://testJson.json";//JSON文件路径
using (System.IO.StreamReader file = System.IO.File.OpenText(jsonfile))
{
using (JsonTextReader reader = new JsonTextReader(file))
{
JObject o = (JObject)JToken.ReadFrom(reader);
return o.tostring();
}
}
}
这个方法有个弊端就是 这个json里面不能有//的注释 否则读取不出来