java - 无法使用 objectmapper 从 html 字符串读取值

标签 java fasterxml

public void testJson() {

        ObjectMapper mapper = new ObjectMapper();
        try {
            String htmlString = mapper.readValue("<!Doctype>", String.class);
        } catch (IOException e) {
            e.printStackTrace();
        }

    }

com.fasterxml.jackson.core.JsonParseException: Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [Source: (String)"";

如何解决这个问题?

最佳答案

我最终使用了 gson。

JsonObject jsonObject = new JsonParser().parse(json).getAsJsonObject();

关于java - 无法使用 objectmapper 从 html 字符串读取值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58122135/

相关文章:

java - Spring : Use Hibernate types without hibernate. cgf.xml

java - jackson JSON : Serialize Array of Objects as their parent type

java - 使用 Linux 一步 yum 安装 32 位 java 1.7

java - POST 到 HTTPS 服务

Java FX 更改前一阶段场景中的标签文本

java - jackson 数据绑定(bind)

java - Fasterxml - 如何从 json 文件中排除对象?

java - springboot 升级后 @JsonProperty 不工作

com/fasterxml/jackson/databind/ObjectMapper 与 Maven 的 java.lang.ClassNotFoundException/NoClassDefFoundError

java - 轻松将库添加到 Eclipse Java Oxygen