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();
}
}
}
}
}