R
R
reus2017-03-31 12:23:10
Java
reus, 2017-03-31 12:23:10

Good tools for working with json in Java?

In general, I have a similar json

{
    "count": 2,
    "next": null,
    "previous": null,
    "results": [
        {
            "parser": 1,
            "date_of_check": "2017-03-24",
            "city": 2,
            "parse_city": "hfghfgh"
        },
        {
            "parser": 1,
            "date_of_check": "2017-03-24",
            "city": 4,
            "parse_city": "Donezk"
        }
    ]
}

I need to get an array from 'results'. Sometimes the contents of this array are nested. Actually the question is, what tools (libraries) would you recommend for working with similar json structures?

Answer the question

In order to leave comments, you need to log in

4 answer(s)
A
al_gon, 2017-03-31
@reus

https://github.com/google/gson
https://futurestud.io/tutorials/gson-getting-start...

Z
Zakharov Alexander, 2017-03-31
@AlexZaharow

Oddly enough, I would recommend the Mongo driver. It doesn't matter if it's a driver. Data can be put into it without loading data from the Mongo server.
mvnrepository.com/artifact/org.mongodb/mongo-java-... (There is a newer version)
Declare a variable for your array:

import com.mongodb.*;
import com.mongodb.util.JSON;

BasicDBObject json = (BasicDBObject) com.mongodb.util.JSON.parse(json_str);
BasicDBList result = (BasicDBList)json.get("result");

You can also use Nashorn . This allows you to use JavaScript in Java at all, but you have to get used to using it. But the thing is awesome.

R
Rou1997, 2017-03-31
@Rou1997

For Android - standard org.json.*for everything else - don't use Java.

S
Sergey Vashchenko, 2017-04-03
@Simipa

https://github.com/FasterXML/jackson - great liba

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question