【json.net】xml转换为json格式时,如何将指定节点转换成数组
[已解决问题]
浏览: 2242次
1 using System.Xml.Linq; 2 using Newtonsoft.Json; 3 4 5 Response.ContentType = "application/json"; 6 7 XDocument xdoc = XDocument.Load(path); 8 9 Response.Write(JsonConvert.SerializeXNode(xdoc));
xml 片段 :
<specialty nameCN="电测"> <step> <signer staffID="800706" nameCN=""><![CDATA[]]></signer> </step> <step> <signer staffID="090477" nameCN=""><![CDATA[]]></signer> </step> </specialty> <specialty nameCN="节能"> <step> <signer staffID="800608" nameCN=""><![CDATA[]]></signer> <signer staffID="800808" nameCN=""><![CDATA[]]></signer> </step> <step> <signer staffID="800602" nameCN=""><![CDATA[]]></signer> <signer staffID="800803" nameCN=""><![CDATA[]]></signer> </step> </specialty>
//输出 json 结果
{ "@nameCN": "电测","step": [ { "signer": { "@staffID": "800706","@nameCN": "","#cdata-section": } },{ "signer": { "@staffID": "090477","#cdata-section": } } ] },{ "@nameCN": "节能","step": [ { "signer": [ { "@staffID": "800608","#cdata-section": },{ "@staffID": "800808","#cdata-section": } ] },{ "signer": [ { "@staffID": "800602",{ "@staffID": "800803","#cdata-section": } ] } ] }