【发布时间】:2017-08-09 00:27:21
【问题描述】:
在反序列化我的字符串并使用以下代码将其转换为 JSON 之后:
JSONObject returnValue = new JSONObject();
String toJson = null;
try
{
Object otherObjectValue = SerializationUtils
.deserialize(myBytesArray);
Gson gson = new Gson();
toJson = gson.toJson(otherObjectValue);
returnValue.put(key, toJson);
}
JSON 的某些部分仍然有类似的内容:
{ "key":"ATTRIBUTE_LIST", "value":"{\"attributeContract\":[{\"scope\":\"sso\",\"name\":\"SAML_SUBJECT\",\"description\":\"Click to Edit\",\"required\":true}]}"}
这意味着所有内容:
"{\"attributeContract\":[{\"scope\":\"sso\",\"name\":\"SAML_SUBJECT\",\"description\":\"Click to Edit\",\"required\":true}]}"
是一个字符串,而不是另一个具有字段的对象。我可以做些什么来通过 JSONObject 进行清理以使其正确地成为 JSON?
【问题讨论】:
-
什么是
myBytesArray?SerializationUtils是什么? -
如果
otherObjectValue已经是一个JSONObject,那么你再toJson它,你会得到一个json对象作为一个字符串 -
@cricket_007 myBytesArray 是 byte[] variableName 类型的变量。 SerializationUtils 来自 apache commons。 otherObjectValue 不是 JSONObject
-
显示完整的 json 结构
标签: java json serialization gson