我有一个 DTO(数据传输对象)对象作为模型,其中包含来自收到的响应的数据。我只需要将标题/列下的值导出到文本文件。不需要导出列名或标题。我能够在XmlSerializer
. 但找不到任何文本序列化程序。我的模型如下:
public class ResponseGradeDto
{
[XmlIgnore]
[XmlElement(ElementName = "GRADEID")]
public Guid Id { get; set; }
[XmlElement(ElementName = "GRADENAME")]
public string Name { get; set; }
[XmlElement(ElementName = "GRADECODE")]
public string Code { get; set; }
public List<GradeQualitySpecDto> QualitySpecItem { get; set; }
}
我尝试了以下代码:
System.Xml.Serialization.XmlSerializer xmlSerializer = new System.Xml.Serialization.XmlSerializer(responseGradeDto.GetType());
using (StringWriter textWriter = new StringWriter())
{
xmlSerializer.Serialize(textWriter, responseGradeDto);
string a = textWriter.ToString();
return textWriter.ToString();
}
假设我的模型如下:
{
"name": "My Name",
"code": "1234",
"information": "My Info",
"gradeQualitySpecItem": [
{
"propertyid": "100",
"propertyname": "PropertyName1",
"target": 10,
"sigma": 20
},
{
"propertyid": "200",
"propertyname": "PropertyName2",
"target": 10,
"sigma": 30
}]
}
我需要在文本文件中输出如下:
AL300 SAMPLE(Some hard coded text)
My Name
1234
My Info
PROP-SUMMARY
100
PropertyName1
10
20
PROP-SUMMARY
200
PropertyName2
10
30
end AL300 SAMPLE(end of file)
如果它是列表,我将得到低于列表的输出。任何人都可以帮助我吗?