Usingusing Newtonsoft.json; " Application/json " = xdocument.load (path); Response.Write (Jsonconvert.serializexnode (Xdoc));
XML fragment:
<specialty namecn="Electrical Measurement"> <step> <signer staffid="800706"namecn=""><! [cdata[]]></signer> </step> <step> <signer staffid="090477"namecn=""><! [cdata[]]></signer> </step> </specialty> <specialty namecn="Energy Saving"> <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>
Output JSON results:
{ "@nameCN":"Electrical Measurement", "Step": [ { "signer": { "@staffID":"800706", "@nameCN":"", "#cdata-section": } }, { "signer": { "@staffID":"090477", "@nameCN":"", "#cdata-section": } } ]},{ "@nameCN":"Energy Saving", "Step": [ { "signer": [ { "@staffID":"800608", "@nameCN":"", "#cdata-section": }, { "@staffID":"800808", "@nameCN":"", "#cdata-section": } ] }, { "signer": [ { "@staffID":"800602", "@nameCN":"", "#cdata-section": }, { "@staffID":"800803", "@nameCN":"", "#cdata-section": } ] } ]}
The above results are marked in red is the difference,step under a plurality of signer nodes, the output signer is an array ,
only 1 signer node output signer is not an array , how to output a number when there is only one signer node
How to convert a specified node to an array when json.net XML is converted to JSON format