How to get property from dynamic JObject programmatically

前端 未结 3 575
甜味超标
甜味超标 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:28

    Assuming you're using the Newtonsoft.Json.Linq.JObject, you don't need to use dynamic. The JObject class can take a string indexer, just like a dictionary:

    JObject myResult = GetMyResult();
    returnObject.Id = myResult["string here"]["id"];
    

    Hope this helps!

提交回复
热议问题