[{"name":"直辖市","cityList":[{"CityID":"2","cityName":"上海 ","cityEname":"Shanghai"}]}]
怎么转化成对象
我在解析的时候无线报错
:annot deserialize the current JSON array (e.g. [1,2,3]) into type 'ConsoleApplication5.Root' because the type requires a JSON object (e.g. {\"name\":\"value\"}) to deserialize correctly.\r\nTo fix this error either change the JSON to a JSON object (e.g. {\"name\":\"value\"}) or change the deserialized type to an array or a type that implements a collection interface (e.g. ICollection, IList) like List that can be deserialized from a JSON array. JsonArrayAttribute can also be added to the type to force it to deserialize from a JSON array.\r\nPath '', line 1, position 1
public class CityListItem
{
public int CityID { get; set; }
public string cityName { get; set; }
public string cityEname { get; set; }
}
public class PolicyCity
{
public string name { get; set; }
public List<CityListItem> cityList { get; set; }
}
public class PolicyRoot
{
public PolicyCity PolicyCity { get; set; }
}
数据库数据= [{"name":"直辖市","cityList":[{"CityID":"2","cityName":"上海 ","cityEname":"Shanghai"}]}]
var city = JsonConvert.DeserializeObject<PolicyRoot>(数据库数据);