Java - write a JSON file

Java - write a JSON file

Professor Saad

7 лет назад

66,998 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

@Userabs
@Userabs - 18.05.2023 20:40

شكرا لك ,, هذا الكود مع تغيير القيم

JSONObject obj = new JSONObject();
obj.put("name", "b");
obj.put("age", "20");

JSONArray list = new JSONArray();

list.add("jeddah");
list.add("makkah");
list.add("madinah");

obj.put("city", list);

try(FileWriter file = new FileWriter("testJSON.json",true) ){
file.write(obj.toString());
file.flush();
}catch(Exception e){
e.printStackTrace();
}

System.out.println(obj);

Ответить
@Garfield_Minecraft
@Garfield_Minecraft - 12.04.2023 16:38

I wanna mod minecraft that's why i learn basic about java and json file

Ответить
@infini667
@infini667 - 09.07.2022 05:14

thanks! but you could explain better why we need to create the JSON array, for example... I'm glad you explained why we should use the file writer inside the try parentheses. ty!

Ответить
@Timm2003
@Timm2003 - 02.02.2022 21:26

Totally agree to the top comment, everything is clear and very good explained, thank u!

Ответить
@anshuakansha2976
@anshuakansha2976 - 01.11.2021 20:04

sir I am not able to import the JSONObject in my java project why so?

Ответить
@danielmarcosmunoz6574
@danielmarcosmunoz6574 - 28.08.2021 13:59

Don't works

Ответить
@PihFrags
@PihFrags - 11.06.2021 12:42

Great work! Really easy to understand ;)

Ответить
@alimedani0296
@alimedani0296 - 02.06.2021 22:25

Thank You So Much Sir!!

Ответить
@enjohsophie
@enjohsophie - 06.04.2021 23:23

2021 April 6th.

Ответить
@sravanimajji8780
@sravanimajji8780 - 23.09.2020 11:22

Could you please provide a video on merge json files

Ответить
@RanjeetkumarYadav
@RanjeetkumarYadav - 10.03.2020 18:21

On point and clearly explained. Good work

Ответить
@agalyjumaklychev2868
@agalyjumaklychev2868 - 02.01.2020 19:12

Can you make a turorial on how to generate a json payload from json schema please

Ответить
@vladanulardzic5859
@vladanulardzic5859 - 28.11.2019 17:58

Everything is "nice & clear" ! Couldn't be more simple ! Thank you. Keep on with such a practical examples.

Ответить
@atularya7124
@atularya7124 - 10.05.2019 08:38

where will i get the created json file ?

Ответить
@kalyanijoshi6884
@kalyanijoshi6884 - 24.04.2019 06:14

How to append the json file ? I am writing some performance logs and at run time i want to append the output

Ответить
@alexchile2653
@alexchile2653 - 21.01.2019 23:06

I am trying to create a json file but reading the data from a mysql table. Can you do that??????

Ответить
@youtubepooppismo5284
@youtubepooppismo5284 - 13.01.2019 11:02

Very helpful, I used it as a DataBase.

Ответить
@sanaamjad5284
@sanaamjad5284 - 06.01.2019 14:09

error -> filewriter could not resolve to a type

Ответить
@franciscojavierramirezhern8588
@franciscojavierramirezhern8588 - 31.10.2018 07:13

Thanks Saad. Greeting from Mexico.

Ответить
@uttamkumarsharma2192
@uttamkumarsharma2192 - 15.09.2018 18:04

i am getting error in the import org.json.simple.JSONObject; package and where to keep the JSON file ????

Ответить
@user-th8mx8rf5x
@user-th8mx8rf5x - 06.09.2018 19:00

How can I splite it in many lines

Ответить
@yifanxu3423
@yifanxu3423 - 05.09.2018 00:46

where is that myJSON.json saved so that when I use fileReader I am able to pass the name as the parameter?

Ответить
@architect8675
@architect8675 - 04.08.2018 03:44

PERFECT.
WHY NO ONE ELSE UPLOAD A SIMPLE AND SPECIFIC CONTENT SUCH LIKE THIS ?

Ответить
@Rafa_guitars
@Rafa_guitars - 22.06.2018 06:20

How do I get rig of the " " in the key

Ответить
@OmgThatsIncredible
@OmgThatsIncredible - 09.04.2018 02:48

Where is the FileWriter class? Im confused

Ответить
@XhekiTanPT
@XhekiTanPT - 06.01.2018 14:09

how to append data without replacing it?

Ответить