Why am I getting "uses unchecked or unsafe operations" error everytime i compile? What's wrong with the code? I copied the exact same code from this tutorial http://www.mkyong.com/java/json-simple-example-read-and-write-json/
import java.io.FileWriter;
import java.io.IOException;
import org.json.JSONArray;
import org.json.JSONObject;
public class JsonSimpleExample {
public static void main(String[] args) {
JSONObject obj = new JSONObject();
obj.put("name", "mkyong.com");
obj.put("age", new Integer(100));
JSONArray list = new JSONArray();
list.add("msg 1");
list.add("msg 2");
list.add("msg 3");
obj.put("messages", list);
try {
FileWriter file = new FileWriter("c:\\test.json");
file.write(obj.toJSONString());
file.flush();
file.close();
} catch (IOException e) {
e.printStackTrace();
}
System.out.print(obj);
}
}
org.json.simple
library is not generic-aware. TheJSONArray
class extends an unparameterizedArrayList
, which is probably where the warnings are coming from. – Barnabas