100分跪求高手json转xml(xml结构有要求)
下面字符串是需要转换的Json示例(结构)
{"head":{"applyDate":"2012-12-21","service":"xh_app_test_get","version":"1.0","system":"system1","applyID":"1","error":false,"replyID":"1","replyDate":"2014-03-17 09:24:00"},"body":{"Status":1,"Error":"","List":[{"TestId":"0","Type":"普通考试","Name":"2013-2014期末考"}]}}
需要转成下面的xml的字符串示例(结构)
<?xml version="1.0" encoding="utf-8"?> <apply><head><set name="applyDate">2012-12-21</set><set name="applyID">1</set><set name="error">False</set><set name="replyDate">2014-03-17 09:24:00</set><set name="replyID">1</set><set name="service">xh_app_test_get</set><set name="system">android</set><set name="version">1</set></head><body><set name="Status">1</set><set name="Error"></set><set name="List" type="array"><set name="TestId">0</set><set name="Type">普通考试</set><set name="Name">2013-2014期末考</set></set></body></apply>
Json里面的list属性可能存在数组的情况,所以转换的时候必须验证,如果是数组,xml要带上type=array的标记,跪求高手一个针对此结构的通用的方法
------解决方案--------------------Json的结构定义的不错,解析如下,需要引用json.Net
JsonClass m = JsonConvert.DeserializeObject<JsonClass>(File.ReadAllText("Json.Txt"));
.......
public class JsonClass
{
public Head head { get; set; }
public Body body { get; set; }
}
public class Head
{
public string applyDate { get; set; }
public string service { get; set; }
public string version { get; set; }
public string system { get; set; }
public int applyID { get; set; }
public bool error { get; set; }
public int replyID { get; set; }
public string replyDate { get; set; }
}
public class Body
{
public int Status { get; set; }
public string Error { get; set; }
public List<Test> List { get; set; }
}
public class Test
{
public int TestId { get; set; }
public string Type {