Read json with gson

Asked

Viewed 81 times

0

I would like to read the JSON below with GSON, put each line in a POJO and add in one ArrayList. But I can’t read JSON.

{"user_id":"K4cXASVRZHM6l_t0l_kBzQ","name":"Rob","review_count":238,"friends":"7VQ46TLFWcJ9NC-Sf9r0cQ, GEbyCpz3QmMh23kYcFS_sg, QDFF2MmjuQpeBGTf4yCQZg, Wz0ZiO-tD-QlGBNlX4JZng, 5bfzMNW7lrLXeWB5YG375g"}

{"user_id":"8AUGRc11vpsRtWAltI4jBA","name":"Emily","review_count":29, "friends":"kIkVDAxrvuLmHw86QWG-YQ, eXYhS1UyJc_Y70kJj6yl_A, BeoIUVPMCSYom7KANYQ0ng, R_lyLZuewPOJYH3k8oAhPw, ujY7b27NQ6pFcUuLYYK9BA, JNh4hmFuC40QhQvFToLeQw, 2wWMgBlRmUvli3MBRTlISA"}

{"user_id":"07MFiMnhPoTpQCNYcqGyBQ","name":"Eddie","review_count":24, "friends":"wTvvYzGrmeQYkZ1QDTRi0w, OIMBD_tc_Bu2Ro1UdaDYsw, zZyF0GPjjb5qp63ebUyHcw, 3b1zZxhzQc7lIdFk6fJDxQ, o0eSwQKB04e3SxwqIfhexA, n5MRQzcvCVK2uR43LWxkoQ, xJprckZNAp9v0Vzd-7km7g"}

I tried so:

public static void main(String[] args) throws FileNotFoundException {
    Gson gson = new Gson();

    JsonReader reader = new JsonReader(new FileReader("yelp_academic_dataset_user.json"));

    List<NoUsuario> data = gson.fromJson(reader, NoUsuario);
}
  • Try to post what you have already tried to do, so that we can better help you, this way the question becomes very broad.

  • Possible duplicate of: https://answall.com/questions/232797/ler-json-com-a-biblioteca-gson

  • Possible duplicate of Read json with GSON library

  • I tried what they sent as a possible duplicate but could not. I think my way of doing fromJson is wrong. As you would do?

  • Cintia, try to add the code you’ve already made, then we’ll see where you might be missing ;)

  • I tried with List[Nousuario], but it won’t

  • What exception are you getting? Edit your question and put it there.

  • You need to put your class code NoUsuario to also analyze.

Show 3 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.