c# - what is $"type" in a json object and How to deserialize it to my model
问题描述
So i have made an api call and received this object back
[
{
"$type": "foo.Api.bar.Entities.foo, foo.Api.bar.Entities",
"id": "a2",
"displayName": "A2",
"statusSeverity": "Good",
"statusSeverityDescription": "No Exceptional Delays",
"bounds": "[[-0.0857,51.44091],[0.17118,51.49438]]",
"envelope": "[[-0.0857,51.44091],[-0.0857,51.49438],[0.17118,51.49438],[0.17118,51.44091],[-0.0857,51.44091]]",
"url": "/Road/a2"
}
]
I have no clue what
"$type": "foo.Api.bar.Entities.foo, foo.Api.bar.Entities",
is and i'm not sure how to design my model to take it in?
public class Road
{
public string Id { get; set; }
public string DisplayName { get; set; }
public string StatusSeverity { get; set; }
public string StatusSeverityDescription { get; set; }
public string Bounds { get; set; }
public string Envelope { get; set; }
public string Url { get; set; }
}
what is $"type" and how should i go about trying to deserialize it into my model, which i will then map into my DTO?
解决方案
The $
sign related to the data source not to JSON itself, to deserialize it use the following :
[JsonProperty(PropertyName = "$type")]
public string PropertyName{ get; set; }
推荐阅读
- r - 如何使用实验的重复进行绘图并执行标准。图中重复的偏差?
- excel - 如何将多个搜索添加到单个代码
- flutter - InheritedWidget 在小部件树 Flutter 中将数据设为 null
- php - Mysql:按日期交集选择,而不是之间
- c# - 任意大小的 C# ValueTuple
- javascript - 如何防止通过 JavaScript 访问我的网站
- php - 为什么我没有从数据库中获取 $user_name?
- javascript - RxJS:将对象键映射到可观察对象
- swift - 使用故事板中定义的自定义类
- c# - 在 ASP.NET Core 中使用 except 方法时显示不正确的答案