0
我有以下的JSON:如何反序列化JSON自定义类型
{
"ExitCode": 1,
"ErrorMessage": "",
"NumberOfMatches": 9,
"NumberOfExtractFrames": 3,
"ProcessingTime": 111,
"MatchResult": [
{
"TopLeft": "2, 8",
"BottomRight": "377, 157",
"Confidence": 1.0,
"HighConfidenceLevel": true,
"SearchFrame": "77, 69, 36, 26",
},
{
"TopLeft": "2, 169",
"BottomRight": "377, 318",
"Confidence": 0.99999982118606567,
"HighConfidenceLevel": true,
"SearchFrame": "77, 230, 36, 26",
},
...
和创建的类:
public class JsonParse
{
public int ExitCode { get; set; }
public string ErrorMessage { get; set; }
public int NumberOfMatches { get; set; }
public int NumberOfExtractFrames { get; set; }
public int ProcessingTime { get; set; }
public List<MatchResult> MatchResult { get; set; }
}
public class MatchResult
{
public Coordinate TopLeft { get; set; }
public Coordinate BottomRight { get; set; }
public decimal Confidence { get; set; }
public bool HighConfidenceLevel { get; set; }
//public Tuple<int, int, int, int> SearchFrame { get; set; }
}
public class Coordinate
{
public int X { get; set; }
public int Y { get; set; }
}
当然
,它崩溃当我尝试这样做:
_jsonParse = JsonConvert.DeserializeObject<JsonParse>(jsonParseString);
我尝试创建一个转换器:
public class CoordinateConverter : CustomCreationConverter<Coordinate>
{
public override Coordinate Create(Type objectType)
{
return new Coordinate();
}
}
和
_jsonParse = JsonConvert.DeserializeObject<JsonParse>(jsonParseString, new CoordinateConverter());
这是行不通的。如何正确声明和使用转换器?
你什么错误? – SLaks
将值“2,8”转换为键入“Domain.Coordinate”时出错 –