c# - 'Newtonsoft.Json.Linq.JArray' does not contain a definition for -
i have following json:
{ "ok": true, "resp": [ { "aaa": 111, "bbb": "xyz", "ccc": [ {...}, { "ddd": "hello", "eee": 666, }, {...} ], "read": false }, {...}, {...} ] }
and c# code:
dynamic my_obj = jsonconvert.deserializeobject(json); var resps = my_obj.resp; var x = ((ienumerable<dynamic>)resps).cast<dynamic>() .where(p => p.ccc.eee == 666).count();
and below error:
'newtonsoft.json.linq.jarray' not contain definition 'eee'.
i know, iterate through elements in 'resps' , count elements, element 'ccc.eee' equals 666, possible in 1 line linq?
since ccc
array, need iterate on it.
count number of eee=666:
int x = ((ienumerable<dynamic>)resps).sum( p => ((ienumerable<dynamic>)p.ccc).count(o => o.eee == 666));
count number of objects in resp having @ least 1 eee=666:
int x = ((ienumerable<dynamic>)resps).count( p => ((ienumerable<dynamic>)p.ccc).any(o => o.eee == 666));
Comments
Post a Comment