通过AWS Java SDK发送带有声音的iOS的SNS(AWS)消息应该是什么Json字符串?

use*_*622 2 java amazon-web-services apple-push-notifications amazon-sns ios

我绝对打破了我的脑袋.我有代码,用于发送iOS的SNS(AWS):

PublishRequest publishRequest = new PublishRequest("arn:aws:sns:us-east-1:my:topic", messageBody);
Run Code Online (Sandbox Code Playgroud)

当我像这样经过Json时,它工作正常:

{"message": "ldjldkjlk"}
Run Code Online (Sandbox Code Playgroud)

但我当然需要声音通知我,没有什么对我有用.我尝试使用Json,当我将它传递给SNS GUI时,它就是这样的:

{"message": { 
    "default": "HERE IS AN ALERT, BADGE, and SOUND",
    "APNS_SANDBOX": "{\"aps\": {\"alert\":\"HERE IS AN ALERT, BADGE, and SOUND!\",\"badge\": 1,\"sound\":\"bingbong.aiff\"}}"
}}
Run Code Online (Sandbox Code Playgroud)

但我得到错误:

{"timestamp":1435334944602,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read JSON: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@2db14d22; line: 1, column: 15]; nested exception is com.fasterxml.jackson.databind.JsonMappingException: Can not deserialize instance of java.lang.String out of START_OBJECT token\n at [Source: java.io.PushbackInputStream@2db14d22; line: 1, column: 15]","path":"/sns/send"}
Run Code Online (Sandbox Code Playgroud)

他们用PublishRequest做了什么?我应该通过什么?如果有人帮助我会很棒!

use*_*622 9

天哪,我找到了自己的答案应该是这样的:

String message = "{\"apn\": { \n" +
                    "    \"default\": \"HERE IS AN ALERT, BADGE, and SOUND\",\n" +
                    "    \"APNS_SANDBOX\": \"{\\\"aps\\\": {\\\"alert\\\":\\\"HERE IS AN ALERT, BADGE, and SOUND!\\\",\\\"badge\\\": 1,\\\"sound\\\":\\\"bingbong.aiff\\\"}}\"\n" +
                    "}}";
            publishRequest.setMessage(message);
            publishRequest.setMessageStructure("json");
Run Code Online (Sandbox Code Playgroud)