L
L
LinuxGod2020-04-25 23:31:31
Java
LinuxGod, 2020-04-25 23:31:31

Convert string to JSON in Java?

I have a string:
(this is a list of primary school students)
I need to do the following from this line:
{
"students": [
{
"sur": "Kozlov",
"mark": 3,
"subject": "Mathematics"
},
(and so on for all students)
]}

Please help me, what function should I use ? How to remake?
Thanks in advance

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Denis Zagaevsky, 2020-04-26
@zagayevskiy

Well, the original string is not JSON, so you need to parse it according to the known structure, create objects and convert it to JSON with some GSON. For parsing in this case, regular expressions are enough, it should turn out quite simply.

I
ilya_kas, 2020-04-27
@ilya_kas

You connect maven to the project. Then you connect gson https://mvnrepository.com/artifact/com.google.code...
Using gson, you can translate to json, read the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question