lr1 -> task_1 -> e3-e8
This commit is contained in:
34
lr10/task_1/e3.java
Normal file
34
lr10/task_1/e3.java
Normal file
@@ -0,0 +1,34 @@
|
||||
package lr10.task_1;
|
||||
|
||||
import java.io.FileWriter;
|
||||
import org.json.simple.JSONArray;
|
||||
import org.json.simple.JSONObject;
|
||||
|
||||
public class e3 {
|
||||
public static void main(String[] args) {
|
||||
JSONObject library = new JSONObject();
|
||||
JSONArray books = new JSONArray();
|
||||
|
||||
JSONObject book1 = new JSONObject();
|
||||
book1.put("title", "Война и мир");
|
||||
book1.put("author", "Лев Толстой");
|
||||
book1.put("year", 1869);
|
||||
|
||||
JSONObject book2 = new JSONObject();
|
||||
book2.put("title", "Мастер и Маргарита");
|
||||
book2.put("author", "Михаил Булгаков");
|
||||
book2.put("year", 1967);
|
||||
|
||||
books.add(book1);
|
||||
books.add(book2);
|
||||
|
||||
library.put("books", books);
|
||||
|
||||
try (FileWriter file = new FileWriter("example-json.json")) {
|
||||
file.write(library.toJSONString());
|
||||
System.out.println("Json файл успешно создан!");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user