gpt4 book ai didi

java - Spring boot json简单导入失败

转载 作者:行者123 更新时间:2023-12-01 17:54:56 24 4
gpt4 key购买 nike

我看到 Spring Boot 有 json simple 的依赖列表

        <dependency>
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>${simple-json.version}</version>
</dependency>

但是我无法在 Spring Boot 应用程序中导入 org.json.JSONObject

可能是什么问题?

最佳答案

编辑

Although spring boot has a dependency on json-simple it's defined as an optional dependency. So you need to add the dependency in your pom as it will not be downloaded automatically with spring boot.

步骤

  1. 将此添加到您的 pom.xml

    <dependency>
    <groupId>com.googlecode.json-simple</groupId>
    <artifactId>json-simple</artifactId>
    <version>1.1.1</version>
    </dependency>
  2. 然后运行命令刷新依赖项

    mvn package
  3. 如果您使用的是 IDE(例如 JetBrains),请刷新/重新导入项目Intellij Idea)。
  4. 在您的类中导入包

    import org.json.simple.JSONObject;
  5. 使用并享受

    import org.json.simple.JSONObject;
    public class Application {

    public static void main(String[] args)

    JSONObject.escape("");
    System.out.println("Done");
    }
    }

关于java - Spring boot json简单导入失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45858173/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com