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 JArray returning null
response.SelectTokens("ClientInfo") not returning any result
response.Children().Where(lst=>lst.SelectToken("ClientInfo").HasValues) is throwing Arg_PlatformNotSupported exception
response.SelectTokens("ClientInfo").Where(lst=>lst.Value<int>()==98367).FirstOrDefault() is returning null
Run Code Online (Sandbox Code Playgroud)
can anyone please help me with how to get all ClientInfo object matching ID in an array of responses?
小智 5
根据文档(https://www.newtonsoft.com/json/help/html/SelectToken.htm),可能的解决方案可以是:
response.SelectTokens("$..ClientInfo[?(@.InternalID=='98367')]").ToList();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
66 次 |
| 最近记录: |