Newtonsoft 反序列化字符串

string json=“[{“name”:”zhangsan”,”age”:”12”},{“name”:”zhangsan”,”age”:”12”}]”

方法1:

JArray arr = (JArray)JsonConvert.DeserializeObject(json);

JObject obj = (JObject)arr[1];

Console.WriteLine(obj["name"]);

Console.WriteLine(arr[1]["name"]);

方法2

一个对象

public class Student

{

  • public string name
  • { get; set; }
  • public int age
  • { get; set; }

}

List<Student> students = JsonConvert.DeserializeObject<List<Student>>(json);

foreach (Student model in students)
{
             //dosomething

}

posted @ 2014-10-08 18:42  居后不争  阅读(1176)  评论(0编辑  收藏  举报