Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何反序列化对.net对象的json响应_C#_Json_Serialization_Deserialization - Fatal编程技术网

C# 如何反序列化对.net对象的json响应

C# 如何反序列化对.net对象的json响应,c#,json,serialization,deserialization,C#,Json,Serialization,Deserialization,我得到了这个错误: Newtonsoft.Json.JsonSerializationException:'无法将当前Json对象(例如{“名称”:“值”})反序列化为类型'System.Collections.Generic.List`1[System.String]”,因为该类型需要Json数组(例如[1,2,3])才能正确反序列化。 若要修复此错误,请将JSON更改为JSON数组(例如[1,2,3]),或更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是in

我得到了这个错误: Newtonsoft.Json.JsonSerializationException:'无法将当前Json对象(例如{“名称”:“值”})反序列化为类型'System.Collections.Generic.List`1[System.String]”,因为该类型需要Json数组(例如[1,2,3])才能正确反序列化。 若要修复此错误,请将JSON更改为JSON数组(例如[1,2,3]),或更改反序列化类型,使其成为可以从JSON对象反序列化的正常.NET类型(例如,不是integer之类的基元类型,也不是数组或列表之类的集合类型)。还可以将JsonObjectAttribute添加到类型中,以强制它从JSON对象反序列化

我的班级:

{
  "resultList": [  
    {  
      "modelId": 11,  
      "modelName": "indves12",  
      "modelLang": "US",  
      "modelVersion": 5,  
      "scoreMap": {  
        "individual": 0.40195605325034905,  
        "vessel": 0.5980439467496509  
      },  
      "bestCategory": "vessel"  
    }  
  ]  
}  
公共类分类器响应
{
公共列表结果列表{get;set;}
}
公共类结果列表
{ 
公共int modelId{get;set;}
公共字符串modelName{get;set;}
公共字符串modelang{get;set;}
公共int模型版本{get;set;}
公共列表scoremap{get;set;}
公共字符串BestCategory{get;set;}
}
公开课成绩表
{
公共双个体{get;set;}
公共双容器{get;set;}
}
}
试试这门课

 public class ClassifierResponse
    {
        public List<resultList> resultLists { get; set; }
    }
     
    public class resultList 
    { 
        public int  modelId {get; set;}
        public string modelName { get; set; }
        public string modelLang { get; set; }
        public int modelVersion { get; set; }
        public List<Scoremap> scoremap { get; set;}
        public string BestCategory { get; set; }
    }
    public class Scoremap 
        {
        public double individual{ get; set; }
        public double vessel { get; set; }
    }
}
公共类分类器响应
{
公共列表结果列表{get;set;}
}
公共类结果列表
{ 
公共int ModelId{get;set;}
公共字符串ModelName{get;set;}
公共字符串modelang{get;set;}
公共int模型版本{get;set;}
公共Scoremap Scoremap{get;set;}
公共字符串BestCategory{get;set;}
}
公开课成绩表
{
公共双个体{get;set;}
公共双容器{get;set;}
}

能否显示类
ClassifierResponse
?现在已将类添加到问题中。@Vernous是否应添加resultlist以进行反序列化,如ClassifierResponse Response=JsonConvert.DeserializeObject(responsestring);大家好,欢迎来到SO。请尝试键入一些文本来描述您所做的更改,因为记分图已从一般
列表更改为单个对象,这一点并不明显。我是否应该反序列化结果列表?@Rodel P.OcfemiaI正在收到响应,但我无法访问响应中的属性。我试着这样做。Response.Resultlist。
 public class ClassifierResponse
    {
        public List<resultList> resultLists { get; set; }
    }
     
    public class resultList 
    { 
        public int  modelId {get; set;}
        public string modelName { get; set; }
        public string modelLang { get; set; }
        public int modelVersion { get; set; }
        public List<Scoremap> scoremap { get; set;}
        public string BestCategory { get; set; }
    }
    public class Scoremap 
        {
        public double individual{ get; set; }
        public double vessel { get; set; }
    }
}
public class ClassifierResponse
{
    public List<ResultList> ResultList { get; set; }
}
 
public class ResultList 
{ 
    public int ModelId {get; set;}
    public string ModelName { get; set; }
    public string ModelLang { get; set; }
    public int ModelVersion { get; set; }
    public Scoremap Scoremap { get; set;}
    public string BestCategory { get; set; }
}
public class Scoremap 
{
    public double Individual{ get; set; }
    public double Vessel { get; set; }
}