C# 使用c语言的IOS推送通知#
我想从c#发送Json字符串,格式如下,用于IOS推送通知:C# 使用c语言的IOS推送通知#,c#,apple-push-notifications,C#,Apple Push Notifications,我想从c#发送Json字符串,格式如下,用于IOS推送通知: { "pushType": "Notification", "notifications": [ { "notificationId": 1, "notificationTitle": "Notification 1", "notificationText": "You are reading your notification 1
{
"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);
希望对您有所帮助。请展示您发送通知时使用的代码,并提及您正在使用的任何库。感谢您的回复,但我使用的是.net.40,javascriptserializer在此版本中不可用。是否有其他方法您好,您可以在.net v4.0中使用Javascript序列化程序。您只需要添加System.Web.Extensions引用。然后,只需在代码的开头添加“usingsystem.Web.Script.Serialization;”。