我的网站将 JWT(内置 php)发送到我用 Java 开发的应用程序。
JWT 在名为 DATI 的自定义字段中包含一个 JSON 字符串。我使用库 JJWT 来描述 DATI 字段中包含的字符串:
Claims MY_CLAIMS = Jwts.parser().setSigningKey(SECRET_KEY__Byte).parseClaimsJws(STRING_JWT).getBody();
ArrayList ARRAY = MY_CLAIMS .get("DATI", ArrayList.class);
String DECODED_STRING_INSIDE_DATI =String.valueOf(ARRAY);
我以正确的方式得到字符串“DECODED_STRING_INSIDE_DATI”(即 JSON 字符串),但由于某种原因,引号 (") 被删除:
[{id=3, id_rivenditore=-1, id_cliente=-1, ip_address=192.168.1.6, nome=DonalDuck, note=ByBye, enabled=1}]
我在“ https://jwt.io/ ”中测试了 STRING_JWT,我得到了正确的引号:
{
"iss": "www.mySite.it",
"exp": 1536913435,
"sub": "WebApp",
"DATI": [
{
"id": "3",
"id_rivenditore": "-1",
"id_cliente": "-1",
"ip_address": "192.168.1.6",
"nome": "DonalDuck",
"note": "ByBye",
"enabled": "1"
}
]
}
我真的不知道如何解决它,因为我无法以正确的方式读取 JSON 字符串。我使用杰克逊库来读取 Json 字符串