问题描述
这是我的xml格式
i想用json格式写这个
请帮帮我
private static byte [] GenerateXMLEmployee(string strFirstName,
string strLastName,int intEmpCode,string strDesignation)
{
XmlTextWriter xmlWriter = new XmlTextWriter( @C:\ Empallee.xml,Encoding.UTF8);
XmlTextWriter xmlWriter = new XmlTextWriter(mStream,Encoding.UTF8);
xmlWriter.Formatting =格式化.In缩;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement(Employee);
xmlWriter.WriteStartElement(FirstName) ;
xmlWriter.WriteString(strFirstName);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement(LastName);
xmlWriter.WriteString(strLastName);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement(EmpCode);
xmlWriter.WriteValue(intEmpCode);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement(Designation);
xmlWriter.WriteString( strDesignation);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
xmlWriter.Close();
返回mStream.ToArray();
}
this is my xml format
i want to write this in json format
please help me
private static byte[] GenerateXMLEmployee(string strFirstName,
string strLastName, int intEmpCode, string strDesignation)
{
XmlTextWriter xmlWriter = new XmlTextWriter(@"C:\Employee.xml", Encoding.UTF8);
XmlTextWriter xmlWriter = new XmlTextWriter(mStream, Encoding.UTF8);
xmlWriter.Formatting = Formatting.Indented;
xmlWriter.WriteStartDocument();
xmlWriter.WriteStartElement("Employee");
xmlWriter.WriteStartElement("FirstName");
xmlWriter.WriteString(strFirstName);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("LastName");
xmlWriter.WriteString(strLastName);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("EmpCode");
xmlWriter.WriteValue(intEmpCode);
xmlWriter.WriteEndElement();
xmlWriter.WriteStartElement("Designation");
xmlWriter.WriteString(strDesignation);
xmlWriter.WriteEndElement();
xmlWriter.WriteEndElement();
xmlWriter.WriteEndDocument();
xmlWriter.Flush();
xmlWriter.Close();
return mStream.ToArray();
}
推荐答案
这篇关于如何在c#中编写json格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!