我正在尝试使用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.
任何帮助将不胜感激。
答案 0 :(得分:0)
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;