// SelectToken where để lấy list JToken theo ý muốn
[HttpGet]
public object SelectToken_Where2()
{
JObject o = JObject.Parse(@"{
'SaleName':'Peter','Age':31,
'Stores': ['Lambton Quay','Willis Street'],
'Manufacturers': [
{'Name': 'Acme Co','Products': [{'Name': 'Anvil','Price': 50}]},
{'Name': 'Contoso','Products': [{'Name': 'Elbow Grease','Price': 99.95},
{'Name': 'Headlight Fluid','Price': 4}]}]
}");
// name of all products priced 50 and above
IEnumerable<JToken> pricyProducts = o.SelectTokens("$..Products[?(@.Price >= 50)].Name");
string NameList = "";
foreach (JToken item in pricyProducts)
{
NameList += (string)item +",";
}
return new { NameList };
}
0 Nhận xét