C# 使用JavaScriptSerializer反序列化JSON字符串以返回单个动态对象,而不是键和值数组

C# 使用JavaScriptSerializer反序列化JSON字符串以返回单个动态对象,而不是键和值数组,c#,json,javascriptserializer,C#,Json,Javascriptserializer,考虑C#中的以下JSON字符串: 然后,我尝试使用以下方法将字符串反序列化为C#中的动态对象: JsonConvert/NewtonSoft不是一个选择 您可以使用而不是对象一些ModelDto并对其进行强制转换,我的意思是: public class ModelDto { public string Key {get;set;} public string Value {get;set;} } 或者,您可以使用以下代码按键从字典中获取值: string buyerRegion = d

考虑C#中的以下JSON字符串:

然后,我尝试使用以下方法将字符串反序列化为C#中的动态对象:


JsonConvert/NewtonSoft不是一个选择

您可以使用而不是
对象
一些
ModelDto
并对其进行强制转换,我的意思是:

public class ModelDto {
  public string Key {get;set;}
  public string Value {get;set;}
}
或者,您可以使用以下代码按键从字典中获取值:

string buyerRegion = dict["BuyerRegion"];

或者,您可以按照问题注释中的建议使用ExpandoObject。

尝试了几种方法后,我意识到访问属性就像调用:

obj["BuyerRegion"]

您可以反序列化到
字典
,然后转换为
扩展对象
,如中所示
public class ModelDto {
  public string Key {get;set;}
  public string Value {get;set;}
}
string buyerRegion = dict["BuyerRegion"];
obj["BuyerRegion"]