标签:too public ati parse ima gen nmap class orm
1 [ 2 {"id":1,"name":"花花","hp":10}, 3 {"id":2,"name":"草草","hp":10}, 4 {"id":3,"name":"树树","hp":10} 5 ]
1.先创建个文本文件
{}数组,[]对象
2加入这个json的应用
.
1 using System; 2 using System.Collections.Generic; 3 using System.Linq; 4 using System.Text; 5 using System.Threading.Tasks; 6 7 namespace _01Json的学习 8 { 9 class skill 10 { 11 public int id; 12 public string name; 13 public int hp; 14 public override string ToString() 15 { 16 return string.Format("id:{0},name:{1},hp:{2}", id, name, hp); 17 } 18 } 19 }
3.
1 using LitJson; 2 using System; 3 using System.Collections.Generic; 4 using System.IO; 5 using System.Linq; 6 using System.Text; 7 using System.Threading.Tasks; 8 9 namespace _01Json的学习 10 { 11 class Program 12 { 13 static void Main(string[] args) 14 {//解析json文本文档。json可以代表数组,对象,一个变量 15 //*************方法二用list*************** 16 List<skill> list = new List<skill>(); 17 18 //**********方法一 ******************** 19 JsonData jd = JsonMapper.ToObject(File.ReadAllText("jsion.txt"));//JsonData在这里代表数组 这个txt要在bin文件夹下的debug下 20 foreach (JsonData item in jd) 21 { 22 skill sk = new skill(); 23 JsonData jsid = item["id"]; 24 JsonData jsname = item["name"]; 25 JsonData jshp = item["hp"]; 26 int num = int.Parse(jsid.ToString()); 27 string name = jsname.ToString(); 28 int hp = Convert.ToInt32(jshp.ToString()); 29 Console.WriteLine(num+name+hp); 30 31 //法二 把信息存入数组 32 sk.id = num;//skill类里的东西 33 sk.name = name; 34 sk.hp = hp; 35 list.Add(sk); 36 } 37 38 //法二 39 foreach (var item in list) 40 { 41 Console.WriteLine(item); 42 } 43 } 44 } 45 }
标签:too public ati parse ima gen nmap class orm
原文地址:https://www.cnblogs.com/satanj/p/9676042.html