[英]Convert Json format to xml format
I have the query to select data:我有选择数据的查询:
Public Function GetStaffList(StaffCode As String) As IEnumerable
Dim query = (From c In Staff Where c.StaffID= StaffCode Select c)
Return query
End Function
You can use the DeserializeXNode<\/code> method<\/a> .
您可以使用
DeserializeXNode<\/code>方法<\/a>。
Based on your JSON you'll likely need to specify a root element name for the XML element.
根据您的 JSON,您可能需要为 XML 元素指定根元素名称。 Below I've used "Staff" as the root name.
下面我使用“Staff”作为根名称。
Dim xml = JsonConvert.DeserializeXNode(json, "Staff")
I found this to work:我发现这个工作:
string xml = "";
string json = @"{
'?xml': {
'@version': '1.0',
'@standalone': 'no'
},
'root': {
'object': " + JsonConvert.SerializeObject(object, Formatting.None)
+ "}}";
var xd = JsonConvert.DeserializeXmlNode(json);
using (var sw = new StringWriter()) {
using (var xw = System.Xml.XmlWriter.Create(sw)) {
xd.WriteTo(xw);
xw.Flush();
xml = sw.GetStringBuilder().ToString();
}
}
The problem you may run into in using DeserializeXmlNode is that it will convert long decimals to scientific notation您在使用 DeserializeXmlNode 时可能遇到的问题是它将长小数转换为科学记数法
For example:例如:
{
"imp_currency_exchange": [{
"base_currency_code": "USD",
"exchange_currency_code": "IDR",
"exchange_date": "2022-02-01T16:06:50Z",
"exchange_rate": 14205,
"batch_id": "FXR-20220201_3",
"reverse_exchange_rate": 0.0000703977
}
]
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.