json 问题
程序代码如下:
res=@"{"marks":{"marks":479998,"visitNumber":0,"bikePasswords":[{"password":"4106","affirmNumber":0,"errorNumber":0,"id":113,"createUser":"admin","createDate":"Dec 6, 2016 3:04:06 PM"}],"id":113,"createUser":"admin","createDate":"Dec 6, 2016 3:04:06 PM"},"resultType":"success"}"
程序调用:
List<SPTA.bbb> o = JsonConvert.DeserializeObject<List<SPTA.bbb>>(res);
运行代码报错。如下。
Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[SPTA.bbb]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.
To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object.
Path 'marks', line 1, position 9.
不知道是实体类有问题还是撒的。各位大神看看
通过生成实体类为
public class BikePasswords
{
/// <summary>
///
/// </summary>
public string password { get; set; }
/// <summary>
/// AffirmNumber
/// </summary>
public int affirmNumber { get; set; }
/// <summary>
/// ErrorNumber
/// </summary>
public int errorNumber { get; set; }
/// <summary>
/// Id
/// </summary>
public int id { get; set; }
/// <summary>
/// admin
/// </summary>
public string createUser { get; set; }
/// <summary>
/// Dec 6, 2016 3:04:06 PM
/// </summary>
public string createDate { get; set; }
}
public class Marks
{
/// <summary>
/// Marks
/// </summary>
public int marks { get; set; }
/// <summary>
/// VisitNumber
/// </summary>
public int visitNumber { get; set; }
/// <summary>
/// BikePasswords
/// </summary>
public List<BikePasswords> bikePasswords { get; set; }
/// <summary>
/// Id
/// </summary>
public int id { get; set; }
/// <summary>
/// admin
/// </summary>
public string createUser { get; set; }
/// <summary>
/// Dec 6, 2016 3:04:06 PM
/// </summary>
public string createDate { get; set; }
}
public class bbb
{
/// <summary>
/// Marks
/// </summary>
public Marks marks { get; set; }
/// <summary>
/// success
/// </summary>
public string resultType { get; set; }