I'm using C# VS2012 with JSON.net. I'm trying to implement this simple example in my project.
Meanwhile I'm reading this article which seems to be of a similar situation.
This is my code :
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
private void JSONpath_Tutorial()
{
JObject o = JObject.Parse(@"{
'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')]"); //getting error here
Console.WriteLine(acme);
// { "Name": "Acme Co", Products: [{ "Name": "Anvil", "Price": 50 }] }
}
I'm getting this exception here : Unexpected character while parsing path indexer: ?
Also, the SelectTokens
method is not available in my intellisense. I'm really drawing a blank here. I've been trying for hours.