Search code examples
javajsoncompiler-errorsxml-to-json

Cannot resolve symbol toJSONObject


So I was trying to convert an XML String to JSON, but I keep getting cannot resolve symbol toJSONObject

JSONObject job = new XML.toJSONObject(d2.toString());

I included the dependency,

<dependency>
        <groupId>org.json</groupId>
        <artifactId>json</artifactId>
        <version>20171018</version>
</dependency>

How to solve this problem?


Solution

  • Remove new keyword. Change

    JSONObject job = new XML.toJSONObject(d2.toString());
    

    to

    JSONObject job = XML.toJSONObject(d2.toString());
    

    Because toJSONObject is a static method that returns JSONObject