// SelectToken where để lấy 1 JToken theo ý muốn
[HttpGet]
public object SelectToken_Where()
{
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}]}]
}");
// manufacturer with the name 'Acme Co'
JToken acme = o.SelectToken("$.Manufacturers[?(@.Name == 'Acme Co')]");
string acme_type = acme.Type.ToString();
string Name = (string)acme.SelectToken("Name");
decimal Price = (decimal)acme.SelectToken("Products[0].Price");
return new { acme_type,acme, Name, Price };
}
0 Nhận xét