我在Android应用程序中使用Gson将复杂对象转换为JSON表示.其中一个字段是名为QuickPin的字符串,其中包含加密密码,字符"="由Gson转换为"\ 003d".
Json字符串由C#WEBAPI应用程序使用,但返回"发生错误"消息.
以下JSON返回该错误消息:
{"UserContractID":"929c1399-11c4-490e-8cff-5b1458ac18e2","UserAuthentication":"MethodCombo":{"AuthMethod":[1]},"QuickPin":"mW2n2uTECEtVqWA2B9MzvQ\u003d\u003d"},"CustomerID":0,"OriginID":0,"OriginTypeID":0,"Status":0}
Run Code Online (Sandbox Code Playgroud)
同时这个JSON工作得很好:
{"UserContractID":"929c1399-11c4-490e-8cff-5b1458ac18e2","UserAuthentication":{"QuickPin":"mW2n2uTECEtVqWA2B9MzvQ==","MethodCombo":{"AuthMethod":[1]}},"CustomerID":0,"OriginID":0,"OriginTypeID":0,"Status":0}
Run Code Online (Sandbox Code Playgroud)
有没有办法强制Gson用密码维护字符串= =(以及其他情况如果)字符?
我的Android代码是:
Gson gson = new Gson();
user = new User();
user.UserAuthentication = new UserAuthentication();
user.UserAuthentication.QuickPin = "mW2n2uTECEtVqWA2B9MzvQ==";
user.UserAuthentication.MethodCombo = new MethodCombo();
user.UserAuthentication.MethodCombo.AuthMethod = new ArrayList<Integer>();
user.UserAuthentication.MethodCombo.AuthMethod.add(1);
user.Status = 0;
String jsonRepresentation = gson.toJson(user);
object.put("user", jsonRepresentation);
Run Code Online (Sandbox Code Playgroud)
谢谢
Gson默认转义HTML元字符.您可以禁用此行为.
Gson gson = new GsonBuilder().disableHtmlEscaping().create();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
797 次 |
| 最近记录: |