Converting dynamic type to dictionary C#

前端 未结 7 1251
执念已碎
执念已碎 2021-01-01 11:22

I have a dynamic object that looks like this,

 {
    \"2\" : \"foo\",
    \"5\" : \"bar\",
    \"8\" : \"foobar\"
 }

How can I convert this

7条回答
  •  难免孤独
    2021-01-01 12:09

    You can use Json.Net to deserialize it to dictionary.

    string json = dynamicObject.ToString(); // suppose `dynamicObject` is your input
    Dictionary dictionary = JsonConvert.DeserializeObject>(json);
    

提交回复
热议问题