*如果程序集没有就引用: Newtonsoft.Json.dll
public class Demo {
public string name { get; set; }
public int age { get; set; }
public List phone { get; set; }
}
public class Phone {
public int P1 { get; set; }
public int P2 { get; set; }
}
class Program {
static void Main(string[] args) {
string json="{'name':'ss','age':18,'phone':[{'p1':56789,'p2':12345}]}";
Demo Demo = Newtonsoft.Json.JsonConvert.DeserializeObject(json); Console.WriteLine(Demo.name); Console.WriteLine(Demo.age); Console.WriteLine(Demo.phone[0].P1); Console.WriteLine(Demo.phone[0].P2); Console.ReadKey(); }
回答完毕。希望能帮到你!
可以直接调用JsonHelper.DeserializeObject<List<T>>(json);JsonHelper.DeserializeObject<T>(json)
JsonHelper.DeserializeObject<T>(jsonString)