#Having a error for my IDE eclipse?

22 messages · Page 1 of 1 (latest)

light creek
#

https://www.javatpoint.com/convert-xml-to-json-in-java
I got it from here.

package com.convertxml;
import org.json.*;

public class ConvertXML {
public static String xml= "<?xml version="1.0" ?><root><test attribute="text1">javatpoint</test><test attribute="text2">JTP</test></root>";

public static void main(String[] args) {
// TODO Auto-generated method stub
try {
JSONObject json = XML.toJSONObject(xml);
String jsonString = json.toString(4);
System.out.println(jsonString);

}catch (JSONException e) {
// TODO: handle exception
System.out.println(e.toString());
}

}

}

rustic ravenBOT
#

This post has been reserved for your question.

Hey @light creek! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

cold wyvern
#

What's the error?

rustic ravenBOT
#
https://www.javatpoint.com/convert-xml-to-json-in-java
I got it from here.


package com.convertxml;  
import org.json.*;  
  
public class ConvertXML {  
public static String xml= "<?xml version=\"1.0\" ?><root><test       attribute=\"text1\">javatpoint</test><test attribute=\"text2\">JTP</test></root>";  
  
public static void main(String[] args) {  
// TODO Auto-generated method stub  
try {  
JSONObject json = XML.toJSONObject(xml);   
        String jsonString = json.toString(4);  
        System.out.println(jsonString);  
  
}catch (JSONException e) {  
// TODO: handle exception  
System.out.println(e.toString());  
}  
  
}  
  
  
}
light creek
cold wyvern
#

what's the error?

#

Do you use a build tool (Maven/Gradle)?

#

Can you show your build path?

light creek
cold wyvern
#

you need to include the library

#

Are you using Maven or Gradle?

light creek
#

no idea

#

im still a student

#

im using eclipse IDE

cold wyvern
#

Libraries aren't available by default

#

you need to download and include them in your project

#

In the Javapoint tutorial, Maven is used for that

#

and you add the dependency using

<dependency>  
    <groupId>org.json</groupId>  
    <artifactId>json</artifactId>  
    <version>20180130</version>  
</dependency>  
#

although that version is old

light creek
#

kk ill try

light creek
#

Thank you.