Чтение и запись файла JSON на Java без использования библиотек JSON - PullRequest
0 голосов
/ 21 февраля 2019

Создайте приложение, которое считывает, хранит и выводит данные в файл json.Примечание. Единственная библиотека, которую вы можете использовать, это библиотеки сканеров, строк и / или дат.Вы не можете использовать json, filereader, bufferreader и т. Д.

Пример: {"author": "fizaali12", "author_flair_css_class": null, "author_flair_text": null, "body": "5 продуктов, которые вам следуетникогда не ешьте натощак "," creation_utc ": 1484601504," id ":" dcih4d0 "," link_id ":" t3_5odjx4 "," parent_id ":" t3_5odjx4 "," score ": 1," stickied ": false,"subreddit": "Health", "subreddit_id": "t5_2qh9z"}

Вывод: "author": "fizaali12", "author_flair_css_class": null, "author_flair_text": null, "body": "5продукты, которые вы никогда не должны есть натощак "," creation_utc ": 16.01.2017, 16:18:24," id ":" dcih4d0 "," link_id ":" t3_5odjx4 "," parent_id ":" t3_5odjx4"," score ": 1, 4" stickied ": false," subreddit ":" Health "," subreddit_id ":" t5_2qh9z "," count ": {" the_number_of_non_null_fields ": 10," the longest_field ":" body ", "the longest_field_value_length": 48, "the_highest_score": 1, "the_highest_score_date": 16.01.2017, 16:18:24 PM, "the_most_frequent_words_in_all_comments": [{"желудок": 2}]}}

Это то, что я имею до сих пор о чтении файла.Просто общий класс, в котором читается файл:

открытый класс ScannerExample {

public static void main(String args[]) throws FileNotFoundException {

System.out.print("Enter the file name with its location and extension : ");
Scanner input = new Scanner(System.in);
File text = new File(input.nextLine());

//Creating Scanner instnace to read File in Java
Scanner scnr = new Scanner(text);

//Reading each line of file using Scanner class
int lineNumber = 1;

while(scnr.hasNextLine()){
    String line = scnr.nextLine();
    System.out.println("line " + lineNumber + " :" + line);
    lineNumber++;

}

Мне было интересно, как мне подходить к хранению и выводу информациибез возможности использовать традиционные библиотеки вывода.

...