我想以下列格式从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"
}
]
}
我尝试发送简单的消息但是无法发送字符串数组。 在过去的两天里,我一直在努力帮助我。
答案 0 :(得分:0)
您可以使用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);
希望它有所帮助。