Azure JSON响应反序列化C#
我的JSON响应如下所示Azure JSON响应反序列化C#,c#,json,azure,deserialization,C#,Json,Azure,Deserialization,我的JSON响应如下所示 [ { "faceRectangle": { "top": 214, "left": 472, "width": 450, "height": 450 }, "faceAttributes": { "age": 19.0, "emotion": { "anger": 0.0, "contempt": 0.0, "disgust": 0.0,
[
{
"faceRectangle": {
"top": 214,
"left": 472,
"width": 450,
"height": 450
},
"faceAttributes": {
"age": 19.0,
"emotion": {
"anger": 0.0,
"contempt": 0.0,
"disgust": 0.0,
"fear": 0.0,
"happiness": 0.0,
"neutral": 0.996,
"sadness": 0.003,
"surprise": 0.001
}
}
}
]
我的课程如下:
public class Output
{
public List<FaceRectangle> FaceRectangles { get; set; }
public List<FaceAttribute> faceAttributes { get; set; }
}
public class FaceAttribute
{
public List<Emotion> Emotions { get; set; }
public int age { get; set; }
}
public class Emotion {
public float anger { get; set; }
public float contempt { get; set; }
public float disgust { get; set; }
public float fear { get; set; }
public float happiness { get; set; }
public float neutral { get; set; }
public float sadness { get; set; }
public float surprise { get; set; }
}
public class FaceRectangle
{
public int top { get; set; }
public int left { get; set; }
public int width { get; set; }
public int height { get; set; }
}
公共类输出
{
公共列表面矩形{get;set;}
公共列表面属性{get;set;}
}
公共类FaceAttribute
{
公共列表{get;set;}
公共整数{get;set;}
}
公共课情绪{
公共浮动愤怒{get;set;}
公共浮动蔑视{get;set;}
公共浮动厌恶{get;set;}
公共浮动恐惧{get;set;}
公共浮动幸福{get;set;}
公共浮点数中性{get;set;}
公共浮点数{get;set;}
公共浮点数{get;set;}
}
公共类FaceRectangle
{
公共整数top{get;set;}
公共整型左{get;set;}
公共整数宽度{get;set;}
公共整数高度{get;set;}
}
然而,当我试图反序列化上述响应时,我得到了以下错误。
错误代码显示为“不支持反序列化数组”
有人能帮我吗?
谢谢大家! 尝试使用以下创建的类: 然后,您可以将JSON数组响应反序列化为
ListCan you log format.GetType()?
public class FaceRectangle
{
public int Top { get; set; }
public int Left { get; set; }
public int Width { get; set; }
public int Height { get; set; }
}
public class Emotion
{
public double Anger { get; set; }
public double Contempt { get; set; }
public double Disgust { get; set; }
public double Fear { get; set; }
public double Happiness { get; set; }
public double Neutral { get; set; }
public double Sadness { get; set; }
public double Surprise { get; set; }
}
public class FaceAttributes
{
public double Age { get; set; }
public Emotion Emotion { get; set; }
}
public class RootObject
{
public FaceRectangle FaceRectangle { get; set; }
public FaceAttributes FaceAttributes { get; set; }
}
using Newtonsoft.Json;
...
var json = @"[{""faceRectangle"": {""top"": 214,""left"": 472,""width"": 450,""height"": 450},""faceAttributes"": {""age"": 19.0,""emotion"": {""anger"": 0.0,""contempt"": 0.0,""disgust"": 0.0,""fear"": 0.0,""happiness"": 0.0,""neutral"": 0.996,""sadness"": 0.003,""surprise"": 0.001}}}]";
var deserializedJson = JsonConvert.DeserializeObject<List<RootObject>>(json);