How to get property from dynamic JObject programmatically

前端 未结 3 577
甜味超标
甜味超标 2020-12-09 16:51

I\'m parsing a JSON string using the NewtonSoft JObject. How can I get values from a dynamic object programmatically? I want to simplify the code to not repeat myself for ev

3条回答
  •  粉色の甜心
    2020-12-09 17:27

    Another way of targeting this is by using SelectToken (Assuming that you're using Newtonsoft.Json):

    JObject json = GetResponse();
    var name = json.SelectToken("items[0].name");
    

    For a full documentation: https://www.newtonsoft.com/json/help/html/SelectToken.htm

提交回复
热议问题