C#中读取和解析JSON文件?
public void LoadJson()
{
using (StreamReader r = new StreamReader("file.json"))
{
string json = r.ReadToEnd();
List<Item> items = JsonConvert.DeserializeObject<List<Item>>(json);
}
}
public class Item
{
public int millis;
public string stamp;
public DateTime datetime;
public string light;
public float temp;
public float vcc;
}
你甚至可以在 C# dynamic
不声明 C# Item
类的情况下获取
dynamic array = JsonConvert.DeserializeObject(json);
foreach(var item in array)
{
Console.WriteLine("{0} {1}", item.temp, item.vcc);
}
dynamic ckeckDate = Newtonsoft.Json.JsonConvert.DeserializeObject<dynamic>(ckeckDate_list);//查询条件
string txtbilltype = ckeckDate.txtbilltype;
string txttransname = ckeckDate.txttransname;