SNS - JSON 消息正文解析失败
SNS - JSON message body failed to parse
我正在尝试通过 Amazon SNS 向移动设备发送远程通知。我有一个数据库,其中存储了需要提供给 SNS 的 PublishRequest 的 JSON(有效负载)。我在代码中序列化 json 并将其传递给请求。
问题是 SNS 失败并出现错误:"MESSAGE STRUCTURE - JSON MESSAGE BODY FAILED TO PARSE"
作为一项要求,服务(负责与 SNS 通信并发送通知)必须从数据库 (MySQL) 检索 json。
我错过了什么?
数据库是MySQL,服务是用.Net Core写的
string messageFromDb = JsonConvert.SerializeObject(input.Payload);
var request = new PublishRequest
{
TargetArn = endpoint.EndpointArn,
MessageStructure = "json",
Message = messageFromDb
};
PublishResponse publishResponse = await _client.PublishAsync(request);
JSON 来自数据库:
{"APNS": {"aps": {"alert": "Check out the new!", "sound": "default"}, "category": {"type": "sports"}}}
我也尝试过这个但没有任何运气:
{"default": "something", "APNS": {"aps": {"alert": "Check out the new games!", "sound": "default"}, "game": {"type": "Xbox"}}}
我终于明白了,也许这个答案会对某人有所帮助。数据库中的 JSON 应该是
{"aps": {"alert": "Check out the new!", "sound": "default"}, "category": {"type": "sports"}}
.Net 代码应该是:
AWSRoot obj = new AWSRoot(input.Payload);
var request = new PublishRequest
{
TargetArn = endpoint.EndpointArn,
MessageStructure = "json",
Message = JsonConvert.SerializeObject(obj)
};
PublishResponse publishResponse = await _client.PublishAsync(request);
AWSRoot 是我们为 SNS 创建的根对象
public class AWSRoot
{
public string APNS { get; set; }
public AWSRoot(string payload)
{
APNS = payload;
}
}
我正在尝试通过 Amazon SNS 向移动设备发送远程通知。我有一个数据库,其中存储了需要提供给 SNS 的 PublishRequest 的 JSON(有效负载)。我在代码中序列化 json 并将其传递给请求。
问题是 SNS 失败并出现错误:"MESSAGE STRUCTURE - JSON MESSAGE BODY FAILED TO PARSE"
作为一项要求,服务(负责与 SNS 通信并发送通知)必须从数据库 (MySQL) 检索 json。
我错过了什么?
数据库是MySQL,服务是用.Net Core写的
string messageFromDb = JsonConvert.SerializeObject(input.Payload);
var request = new PublishRequest
{
TargetArn = endpoint.EndpointArn,
MessageStructure = "json",
Message = messageFromDb
};
PublishResponse publishResponse = await _client.PublishAsync(request);
JSON 来自数据库:
{"APNS": {"aps": {"alert": "Check out the new!", "sound": "default"}, "category": {"type": "sports"}}}
我也尝试过这个但没有任何运气:
{"default": "something", "APNS": {"aps": {"alert": "Check out the new games!", "sound": "default"}, "game": {"type": "Xbox"}}}
我终于明白了,也许这个答案会对某人有所帮助。数据库中的 JSON 应该是
{"aps": {"alert": "Check out the new!", "sound": "default"}, "category": {"type": "sports"}}
.Net 代码应该是:
AWSRoot obj = new AWSRoot(input.Payload);
var request = new PublishRequest
{
TargetArn = endpoint.EndpointArn,
MessageStructure = "json",
Message = JsonConvert.SerializeObject(obj)
};
PublishResponse publishResponse = await _client.PublishAsync(request);
AWSRoot 是我们为 SNS 创建的根对象
public class AWSRoot
{
public string APNS { get; set; }
public AWSRoot(string payload)
{
APNS = payload;
}
}