反序列化空的json属性名 [英] Deserialize empty json propertyname
本文介绍了反序列化空的json属性名的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个来自Web api的json对象,它看起来像这样:
I have a json object coming from a web api which looks something like this:
{"":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]}
并且我有相应的C#类用于反序列化:
and I have corresponding C# class for deserialize:
public class Person
{
public int id { get; set; }
public string name { get; set; }
}
public class RootObject
{
public List<Person> Persons { get; set; }
}
但是每当我使用Json.NET反序列化时,RootObject
类中的Persons
属性是
始终为null.
but whenever I deserialize using Json.NET the Persons
property in RootObject
class is
always null.
var c = JsonConvert.DeserializeObject<RootObject>(response);
我知道这个问题非常琐碎,如果有人可以帮助我解决此问题,我非常感谢.
I know the problem is very trivial, I really appreciate if anyone can help me out to fix this up.
推荐答案
如果您更改
{"":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]}
到
{"Persons":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]}
反序列化就很好了.
这篇关于反序列化空的json属性名的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文