简体   繁体   English

想要将 json 字符串转换为包含 xml 的 json 对象

[英]want to convert json string to json object containing xml

I want to convert json string to json object.我想将 json 字符串转换为 json 对象。 I am using the following method.我正在使用以下方法。

public List convertJsonToObject(String json) throws JsonParseException, JsonMappingException, IOException {
  ObjectMapper mapper = new ObjectMapper(); 
  List myObjects = mapper.readValue(json, new TypeReference>() {}); 
  return myObjects; 
}

The problem is that my json string has XML content in it, which gives error because of double quotes.问题是我的 json 字符串中包含 XML 内容,由于双引号而导致错误。 What should I do?我该怎么办?

You need to convert a valid json.您需要转换有效的 json。 I reformatted your incomplete JSON a bit.我重新格式化了您不完整的 JSON。 Please try this one.请试试这个。 You need to escape some characters.您需要转义一些字符。 The " character needs to be escaped. "字符需要转义。

[
  {
    "orderNo":"20139429260",
    "sapRequest":"<?xml version=\"1.0\" encoding=\"UTF-8\" s..",
    "customerResponse":"<?xml version=\"1.0\" e....
   }
]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 无法转换包含“&”或“;”的XML字符串 到JSON对象 - Unable to convert XML string containing '&' or ';' to JSON object 将 Java object 转换为 json 字符串,其中包含 json 字符串已经属性 - Convert Java object to json string containing a json string property already 我想将json对象中的xml字符串数据转换为java中的json - I want to convert xml string data inside json object to json in java 将XML字符串转换为JSON对象对象 - Convert an XML String to a JSON Object Object 如何使用 Java 将包含 JSON 对象的字符串转换为实际的 JSON - How to convert String containing JSON object to actual JSON using Java 有没有一种简单的方法来转换 JavaRDD<String> 包含到自定义 Java 对象的 JSON - Is there a simple way to convert JavaRDD<String> containing JSON to a custom Java object 如何将包含逗号分隔的 json 值的单个字符串转换为单个 json object? - How to convert single String containing a comma separated json values into a single json object? 如何在 Java 中将类似 XML 结构的对象转换为 JSON 字符串? - How to convert an XML structured-like object to a JSON string in Java? 将包含重复字段的对象转换为JSON - Convert object containing repeated fields to JSON 将包含数组的json字符串转换为Java中的Map - Convert json String containing array to Map in Java
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM