小编Nit*_*hya的帖子

Select object based on condition inside a nested array

I have a Jarray of response and inside Jarray there is an array of Clients and based on the condition I need to select the object in Array Json is

JArray response = JArray.Parse(@"[
                  {
                    'ProviderTransactionID': '4c4c5b43-0dd6-490c-9a59-062e25c04019',
                     'IsSuccess': 'False',
                     'ErrorMessages': 'Some error',
                      'ClientInfo': [
                       {
                         'InternalID': '98367',
                         'UniqueID': '',
                         'ErrorMessages': 'ERROR:'
                       },
                       {
                         'InternalID': '98368',
                         'UniqueID': '',
                         'ErrorMessages': 'ERROR:'
                       }
                     ]
                   }
            ]");
Run Code Online (Sandbox Code Playgroud)

For example, I need to select the ClientInfo Object where InternalID=98367

But

response.SelectToken("ClientInfo") returning null

response.SelectToken("ClientInfo") as …
Run Code Online (Sandbox Code Playgroud)

c# json json.net

2
推荐指数
1
解决办法
66
查看次数

模型中使用 JToken 时 Swagger Schema 自引用

我的 API 模型有一个类似于 JArray 类型的属性

public class MyModel
{
   public JArray Credentials { get; set; }
   public string Property1 {get;set;}
}
Run Code Online (Sandbox Code Playgroud)

对于 Credentials Swagger 生成类似

"credentials": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/JToken"
            },
            "nullable": true
          }


Run Code Online (Sandbox Code Playgroud)

模式就像

 "JToken": {
        "type": "array",
        "items": {
          "$ref": "#/components/schemas/JToken"
        }
      }
Run Code Online (Sandbox Code Playgroud)

这里JToken是自引用的,如何避免这种自引用呢?

swagger .net-core swashbuckle

1
推荐指数
1
解决办法
414
查看次数

标签 统计

.net-core ×1

c# ×1

json ×1

json.net ×1

swagger ×1

swashbuckle ×1