【发布时间】:2014-10-29 10:23:28
【问题描述】:
我需要像这样转换一个 dto 对象类:
public class ComplexDto
{
public ComplexDto()
{
ListIds = new List<ListIdsDto>();
}
public string Propertie1 { get; set; }
public string Propertie2 { get; set; }
public IList<int> ListIds { get; set; }
}
到dictionary<string,string>。
这只是一些类的例子,这个类将被用作这样的json对象:
{"Propertie1":"ss","Propertie2":"","ListIds":[1,2,3]}
我需要将此对象作为字符串字典传递给 FormUrlEncodedContent(dictionary)。
我有这个:
var data = new Dictionary<string, string>();
data[string.Empty] = ComplexDto.ToJson();
我想将 ComplexDto.ToJson() 或 ComplexDto 对象转换为 Dictionary 字符串 string。
有什么想法吗?
【问题讨论】:
-
什么是 ListIdsDto?也只有一个类,要用于字典的集合在哪里?
-
什么应该被转换成什么?
-
您希望
ComplexDto看起来是一个字符串吗? -
您是否需要能够将字符串表示形式转换回 ComplexDto 实例?
-
我误读了您的问题,我猜您想将 dto 的属性作为 property.name property.value 的字典返回
标签: c# dictionary