Click here to Skip to main content
15,886,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I am developing a web service which gives json string as output.
At one situation i am converting datatable in this format..

"RCCLUServices": {
"RCCLUService": {
"ServiceID": "70",
"RateCardRegionId": "444",
"ServiceName": "BASIC SERVICE",
"Description": null,
"Price": "$35.99"
}
}


If ou see above output"RCCLUService" has only one child and showing in one set... But when it have multiple childs... it shows like this [ ] like in array format...
Can anyone let me know how to show in array format when we have one child also the below code i use for json serialisation

C#
XmlDocument document = new XmlDocument();

document.LoadXml(dsRcDetasils.GetXml());
                       strSectionChannelDetails.Append(JsonConvert.SerializeXmlNode(document);
Posted

1 solution

There is a difference between a child property and an array. A child property is like

{"parentID":123, "child":{"childID":456}}


An array of three children is

{"parentID":123, "children":[
{"childID":1}, {"childID":2}, {"childID":3}
]}


An array of one child is

{"parentID":123, "children":[{"childID":1}]}


Compare that to the first example of a child property. If the property is an array it has [] even if if the array is empty, has one item, or multiple items. If the property is not an array but another object there are no []

http://www.w3schools.com/json/json_syntax.asp[^]
 
Share this answer
 
Comments
jing567 8-Dec-15 6:14am    
I want to set it in c# code...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900