简体   繁体   English

导入了JSON库Java,但仍然无法解析JSON错误

[英]Imported json library Java, but still getting JSON cannot be resolved error

I started coding on leetcode and then opened it in playground and put that code in my local and imported the json jar, but am still seeing the error that Json cannot be resolved. 我开始在leetcode上编码,然后在操场上将其打开,然后将该代码放入本地并导入json jar,但仍然看到无法解决Json的错误。

error line: return Json.value(input).toString(); 错误行:return Json.value(input).toString();

I have tried the both import jars 我已经尝试了两个进口罐

import org.json. 导入org.json。 ; ; import org.json.simple. 导入org.json.simple。 ; ;

Any help would be greatly appreciated. 任何帮助将不胜感激。

Thanks in advance. 提前致谢。

public static String stringToString(String input) {
    if (input == null) {
    return "null";
        }
        return Json.value(input).toString();
}

If you are trying to run this on leetcode, the jar should be actually present on your application classpath in order for import to work. 如果您尝试在leetcode上运行它,则jar应该实际上存在于您的应用程序类路径中,以便导入工作。 As a test, try running your code in some IDE like eclipse or Intellij. 作为测试,请尝试在eclipse或Intellij等IDE中运行代码。 It will prompt you at compile time about the error. 它会在编译时提示您有关错误的信息。

Json not available in org.json. Json在org.json中不可用。 You may use JSONObject to parse json string like this 您可以使用JSONObject这样解析json字符串

JSONObject jo = new JSONObject(
  "{\"city\":\"chicago\",\"name\":\"jon doe\",\"age\":\"22\"}"
);

See full example Here 在此处查看完整示例

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM