ga3ga3 2016-12-23 02:30 采纳率: 50%
浏览 1774
已采纳

json 反序列化问题。 请各位大神看看 c#

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; }
  • 写回答

4条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥50 swift使用textkit读取大文本文件速度慢的问题
      • ¥20 统信linux360企业浏览器 如何配置扩展程序?(图形界面我知道)
      • ¥100 c/c++实现DoubleArrayTrie
      • ¥30 关于#网络安全#的问题:非对称加密验证
      • ¥20 关于线性代数里施密特正交化和QR分解的疑问
      • ¥15 matlab超类包含解析错误
      • ¥15 python拖拽文件问题
      • ¥15 执行import paddle代码出现错误如何解决?
      • ¥15 hisat2align exited with value 137
      • ¥15 寻找大学生合作开发软件(Delphi)