有人可以帮助我使用正确的JsonPath语法来选择名称为“US \ East”的“位置”吗?
JObject location = new JObject();
location.Add("name", @"US \ East");
JArray locations = new JArray();
locations.Add(location);
JObject properties = new JObject();
properties.Add("locations", locations);
string path = "locations[?(@.name == 'US \\ East')]";
JToken item = properties.SelectToken(path);
最后一行抛出以下异常:
Newtonsoft.Json.JsonException was unhandled
_HResult=-2146233088
_message=Unknown escape chracter: \
HResult=-2146233088
IsTransient=false
Message=Unknown escape chracter: \
Source=Newtonsoft.Json
StackTrace:
at Newtonsoft.Json.Linq.JsonPath.JPath.ReadQuotedString()
at Newtonsoft.Json.Linq.JsonPath.JPath.ParseValue()
at Newtonsoft.Json.Linq.JsonPath.JPath.ParseExpression()
at Newtonsoft.Json.Linq.JsonPath.JPath.ParseQuery(Char indexerCloseChar)
at Newtonsoft.Json.Linq.JsonPath.JPath.ParseIndexer(Char indexerOpenChar)
at Newtonsoft.Json.Linq.JsonPath.JPath.ParsePath(List`1 filters, Int32 currentPartStartIndex, Boolean query)
at Newtonsoft.Json.Linq.JsonPath.JPath.ParseMain()
at Newtonsoft.Json.Linq.JsonPath.JPath..ctor(String expression)
at Newtonsoft.Json.Linq.JToken.SelectToken(String path, Boolean errorWhenNoMatch)
at Newtonsoft.Json.Linq.JToken.SelectToken(String path)
at JsonPath.Program.Main(String[] args)