主要通过 Jobject获取想要序列化的部分对象。
直接上代码
static void Main(string[] args)
{
//先反序列化看看
string json = "{"name": true,"age": "success","hobby": [{"obj1": "6","obj2": "7","obj3": "10"}, {"obj1": "6","obj2": "7","obj3": "10"}]}";
var q = JsonConvert.DeserializeObject<dynamic>(json);
Console.WriteLine(q.name);
//只反序列化hobby为List<Test>
JObject jobj = JObject.Parse(json);
string Data = jobj["hobby"].ToString();
var v = JsonConvert.DeserializeObject<List<Test>>(Data);
Console.WriteLine(v[0].obj2);
Console.ReadLine();
}
public class Test
{
public string obj1 { get; set; }
public string obj2 { get; set; }
public string obj3 { get; set; }
}