Get path of JSON value using JSON.NET

后端 未结 4 843
北恋
北恋 2021-01-11 12:14

I am trying to find a path of a JSON value. Consider the following JSON:

{
    \"car\": {
        \"type\": [{
            \"sedan\": {
                \"mak         


        
4条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-11 12:57

    You could also try the SelectToken method like this:

    var j = JObject.Parse(json);
    var token = j.SelectToken("car.type[0].sedan.make");
    Console.WriteLine(token.Path + " -> " + token.ToString());
    

    Outputs:

    car.type[0].sedan.make -> honda
    

提交回复
热议问题