Converting dynamic type to dictionary C#

前端 未结 7 1245
执念已碎
执念已碎 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:22

    You can do it with jsonSerializer. And it requires System.Net.Extensions reference. Here is a sample code.

    var jss = new JavaScriptSerializer();
    var dict = jss.Deserialize<Dictionary<string,string>>(jsonText);
    var place = dict["8"]; // "foobar"
    
    0 讨论(0)
提交回复
热议问题