【发布时间】:2017-03-31 08:05:19
【问题描述】:
我似乎无法将 Json 的类排成 Linq XML。
c.first、c.second 和 c.third 被突出显示并声明:
“您是否缺少 using 指令或程序集引用。”
var serializer = new JavaScriptSerializer();
var json1 = "[count:[place:{first:1,second:2,third:3}],[place:{first:11,second:22,third:33}],[place:{first:111,second:222,third:333}]]]";
var jsons = serializer.Serialize(json1);
var jsona = serializer.Deserialize<List<jClass>>(jsons);
var xmld = new XDocument(
new XElement("count", jsona.Select(c =>
new XElement("place",
new XElement("first", c.first),
new XElement("second", c.second),
new XElement("third", c.third)
)
))
);
类.cs
public class jClass
{
public jNumber[] count { get; set; }
}
public class jNumber
{
public jTopThree[] place { get; set; }
}
public class jTopThree
{
public int first { get; set; }
public int second { get; set; }
public int third { get; set; }
}
【问题讨论】:
-
c是jClass类型,它只包含属性count,它是jNumber的数组。您实际上要选择哪个值? 1? 22?第333章? -
如何将 jTopThree 等同起来,以便创建 xml 文档中的所有第一个、第二个和第三个?
-
没关系,我知道你的 JSON 应该是什么样子了。您有所需 XML 的示例吗?