以下JSON是我的请求体:
{
"Routes": {
"route1": {
"ClusterId": "cluster1",
"Match": {
"Path": "{**catch-all}",
"Hosts": ["www.aaaaa.com", "www.bbbbb.com"]
}
}
},
"Clusters": {
"cluster1": {
"Destinations": {
"cluster1/destination1": {
"Address": "https://example.com/"
}
}
}
}
}
我正在尝试将其投射为对象,但它不起作用
var reqItems1 = JsonConvert.DeserializeObject<Req>(jsonData);
其中Req
为:
public class Req
{
public RouteConfig Routes { get; set; }
public ClusterConfig Clusters { get; set; }
}
定义了RouteConfig
和ClusterConfig
:
https://microsoft.github.io/reverse-proxy/api/Yarp.ReverseProxy.Configuration.RouteConfig.html
https://microsoft.github.io/reverse-proxy/api/Yarp.ReverseProxy.Configuration.ClusterConfig.html
一切都是空的。如何将请求直接解析为对象?
从附加的JSON中,Routes
和Clusters
属性是键值对。
因此,您的Req
类应如下所示:
public class Req
{
public Dictionary<string, RouteConfig> Routes { get; set; }
public Dictionary<string, ClusterConfig> Clusters { get; set; }
}