IOS推送通知使用c#
本文关键字:通知 IOS | 更新日期: 2023-09-27 18:18:49
我想以以下格式从c#发送Json字符串用于IOS推送通知:
{
"pushType": "Notification",
"notifications": [
{
"notificationId": 1,
"notificationTitle": "Notification 1",
"notificationText": "You are reading your notification 1",
"notificationExpiryDate": "yyyy-MM-dd"
},
{
"notificationId": 2,
"notificationTitle": "Notification 2",
"notificationText": "You are reading your notification 2",
"notificationExpiryDate": "yyyy-MM-dd"
},
{
"notificationId": 3,
"notificationTitle": "Notification 3",
"notificationText": "You are reading your notification 3",
"notificationExpiryDate": "yyyy-MM-dd"
}
]
}
我试图发送简单的消息,但无法发送字符串数组。请帮我解决这个问题,因为我从过去的两天挣扎。
你可以通过使用JavascriptSerializer来实现这一点。下面是一个使用匿名代码声明的代码示例
var obj = new
{
pushType = "Notification",
notification = new[]{
new {
notificationId = 1,
notificationTitle = "Notification 1",
notificationText = "You are reading your notification 1",
notificationExpiryDate = "yyyy-MM-dd"
},
new {
notificationId = 2,
notificationTitle = "Notification 2",
notificationText = "You are reading your notification 2",
notificationExpiryDate = "yyyy-MM-dd"
},
new {
notificationId = 3,
notificationTitle = "Notification 3",
notificationText = "You are reading your notification 3",
notificationExpiryDate = "yyyy-MM-dd"
}
}
};
JavaScriptSerializer serializer = new JavaScriptSerializer();
string outputstring = serializer.Serialize(obj);
希望能有所帮助。