[英]Json.net how to use jsonpath with “$.”
我正在尝试从json使用json.net,如下所示:
String JSONString =
@"[
{
""category"": ""reference"",
""author"": ""Nigel Rees"",
""title"": ""Sayings of the Century"",
""price"": 8.95
},
{
""category"": ""fiction"",
""author"": ""Still Here"",
""title"": ""Test remove title"",
""price"": 12.99,
""isbn"": ""0-553-21311-3""
}
]";
JObject JSONObject;
JSONObject = JObject.Parse(JSONString);
String JSONPath = @"$[0].title";
JSONObject.SelectToken(JSONPath);
异常:
ST.Acxiom.Test.DataJSONTest.DataJSONClass.GetToken: Newtonsoft.Json.JsonException : Property '$' does not exist on JObject.
任何帮助,将不胜感激。
JObject.Parse
会抛出JsonReaderException
和最新的Json.net版本。 您必须使用JToken.Parse
或JsonConvert.DeserializeObject
。 $
。 您可以像这样访问数组项: var jArray = JToken.Parse(JSONString); //It's actually a JArray, not a JObject
var jTitle = jArray.SelectToken("[0].title");
var title = (string)jTitle;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.