我正在使用Step Function方法,该方法使用传递AWS API网关调用的JSON查询(具有应用程序/ json正文映射模板)开始。 一切顺利,但有时客户名称(在JSON中)包含非标准字符,例如é,重音e。随后在StepFunction的输入JSON中用 符号替换它,该符号用于替换未知的,无法识别的或不可表示的字符。
知道如何说服Step Functions保留原始字符吗?我已经检查了发送到API的JSON,它包含é所以在我身边一切似乎都很好。
也许我应该用'\ u00E9'替换它,但我也应该为其他角色替换它,我怎么知道要转换哪些字符?
我检查了JSONString是否为UTF-8编码:
CharsetDetector detector = new CharsetDetector();
detector.setText(jsonO.toJSONString().getBytes());
System.out.println(detector.detect().getName());
这是我调整为发送UTF-8的http帖子:
CloseableHttpClient client = HttpClients.createDefault();
HttpPost httpPost = new HttpPost(
"some_url");
String json = "{\"dna_match\":BLADIEBLA,\"dna_match_info\":\"3rd COUSIN\"}";
StringEntity entity = null;
try {
entity = new StringEntity(json,"UTF-8");
entity.setContentType("application/json;charset=UTF-8");
//entity.setContentEncoding("UTF-8");
entity.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json;charset=UTF-8"));
httpPost.setEntity(entity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json;charset=UTF-8");
CloseableHttpResponse response = client.execute(httpPost);
String responseAsString = EntityUtils.toString(response.getEntity());
client.close();
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(Connect2api.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(Connect2api.class.getName()).log(Level.SEVERE, null, ex);
}
仍然没效果......