【发布时间】:2021-12-16 18:06:42
【问题描述】:
我在 c# 中的应用程序中有对象,我需要将其序列化为 JSON,但我需要将结果 json 自定义为如下所示:
My class :
public class OrderStatus
{
public string title { get; set; }
public int statusNo { get; set; }
public string description { get; set; }
public string message { get; set; }
public string icon { get; set; }
}
我需要把它转换成
{
"1": {
"icon": "orange_warning",
"title": "Pending Processing",
"message":
"We are processing your payment on our end which could take up to 30 minutes",
"description":
"Feel free to continue shopping while we process your payment. You can check the status of your order in Order History at any time."
},
"2": {
"icon": "done_success",
"title": "Order Successfully Placed",
"message": "",
"description":
"We have sent an email to your email address confirming your order."
}
}
json中显示的数字是StatusNo在我的类中我使用这个方法来序列化类
new JavaScriptSerializer().Serialize(model)
【问题讨论】:
-
这个问题质量极低,请阅读How to Ask 并在以后添加回答它所需的适当信息
标签: c# asp.net .net serialization jsonconvert