问题
I have a json object coming from a web api which looks something like this:
{"":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]}
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; }
}
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.
回答1:
I think the Json string is flawed, if you change
{"":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]}
to
{"Persons":[{"id":1, "name":"name1"}, {"id":2, "name":"name2"}]}
it deserializes just fine.
来源:https://stackoverflow.com/questions/14169350/deserialize-empty-json-propertyname