Cannot access properties after JSON deserialization into dynamic

后端 未结 1 1629
隐瞒了意图╮
隐瞒了意图╮ 2021-01-12 18:18

I\'m having some issues accessing dynamic properties after JSON deserialization. Here is the JSON:

{
  \"user\" : { 
       \"511221\" :{ 
        \"timestam         


        
1条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-12 18:40

    You can deserialize your JSON to JObject instead of dynamic, then you can access the property by property name dynamically, for example :

    JObject jObject = JsonConvert.DeserializeObject(response);
    var user = "511221";
    var structures = jObject["user"][user]["structures"][0];
    
    //given JSON input as in this question, 
    //following line will print "structure.62dd1ff1-f96b-22e3-8d4e-22000c20725r"
    Console.WriteLine(structures);
    

    0 讨论(0)
提交回复
热议问题