Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/algorithm/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用c语言的IOS推送通知#_C#_Apple Push Notifications - Fatal编程技术网

C# 使用c语言的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

我想从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);

希望对您有所帮助。

请展示您发送通知时使用的代码,并提及您正在使用的任何库。感谢您的回复,但我使用的是.net.40,javascriptserializer在此版本中不可用。是否有其他方法您好,您可以在.net v4.0中使用Javascript序列化程序。您只需要添加System.Web.Extensions引用。然后,只需在代码的开头添加“usingsystem.Web.Script.Serialization;”。