How to convert a specified node to an array when json.net XML is converted to JSON format

Source: Internet
Author: User
Tags cdata net xml

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.