mojego kodu, aby utworzyć nowy JSONObject i zapisu do pliku:toJSONString() jest zdefiniowana dla danego typu JSONObject
JSONObject obj = new JSONObject();
obj.put("name", "abcd");
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);
Mój problem polega na
file.write(obj.toJSONString());
Mówi, że
The method toJSONString() is undefined for the type JSONObject.
Czy brakuje mi jakiejś biblioteki? Czy nie zamierzam tego źle? Czy istnieje alternatywny sposób na zrobienie tego?
Być może ty meants 'obj.toString()'? –
Próbowałem, ale daje mi errror. – MDEVLP
Jaki błąd daje? –