C#datable to Array转换 [英] C# datable to Array conversion
问题描述
我正在开发一个提供json字符串作为输出的Web服务。
在某种情况下,我正在转换数据表这种格式..
RCCLUServices:{
RCCLUService:{
ServiceID: 70,
RateCardRegionId:444,
ServiceName:基本服务,
描述:null ,
价格:35.99美元
}
}
如果你看到上面的输出RCCLUService只有一个孩子并且在一个集合中显示......但是当它有多个孩子时......它像数组格式一样显示这样的[]
任何人都可以让我知道当我们有一个孩子时如何以数组格式显示以下代码我用于json序列化
< pre lang =C#> XmlDocument docum ent = new XmlDocument();
document.LoadXml(dsRcDetasils.GetXml());
strSectionChannelDetails.Append(JsonConvert.SerializeXmlNode(document);
35.99
}
}
如果你看到上面的输出RCCLUService只有一个孩子并且在一套中显示...但是当它有多个孩子时...就像这样[]就像阵列格式一样...
当我们还有一个孩子时,任何人都可以让我知道如何以数组格式显示以下用于json序列化的代码
XmlDocument document = new XmlDocument();
document.LoadXml(dsRcDetasils.GetXml());
strSectionChannelDetails.Append(JsonConvert.SerializeXmlNode(document);
子属性和数组之间存在差异。子属性类似于
{parentID: 123,chi ld:{childID:456}}
三个孩子的阵列是
{parentID:123,children:[
{childID:1},{childID:2},{childID:3 }
]}
一个孩子的阵列是
{parentID:123,children:[{childID:1}]}
将其与子属性的第一个示例进行比较。如果属性是数组,则它具有[],即使数组为空,有一个项目或多个项目。如果属性不是数组而是另一个对象则没有[]
http://www.w3schools.com/json/json_syntax.asp [ ^ ]
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
XmlDocument document = new XmlDocument();
document.LoadXml(dsRcDetasils.GetXml());
strSectionChannelDetails.Append(JsonConvert.SerializeXmlNode(document);
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
XmlDocument document = new XmlDocument(); document.LoadXml(dsRcDetasils.GetXml()); strSectionChannelDetails.Append(JsonConvert.SerializeXmlNode(document);
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[^]
这篇关于C#datable to Array转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!