I'm using LINQ over a JArray
to filter out the items based on a particular condition and want that result in a separate JArray
.
JArray arrSameClass = (JArray) arrPupilEmailDetails.Where(joSameClass => joSameClass["uClassId"].ToString() == gidClassId.ToString());
But this is giving me an casting exception('unable to cast from IEnumerable<JToken> to JArray'
). I've tried JArray.Parse()
also. Any help ?
JToken. Creates a JArray from an object. The object that will be used to create JArray. The JsonSerializer that will be used to read the object.
JArray(Object[]) Initializes a new instance of the JArray class with the specified content. JArray(JArray) Initializes a new instance of the JArray class from another JArray object.
You can use the JArray(Object)
constructor and pass it your IEnumerable<JToken>
and the enumerable will be evaluated and used to construct the JArray
:
var query = arrPupilEmailDetails.Where(joSameClass => joSameClass["uClassId"].ToString() == gidClassId.ToString());
var arrSameClass = new JArray(query);
Sample fiddle.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With