0

I am trying to parse a large JSON object in Java.

{
"created_at":"Fri May 23 18:40:13 +0000 2014",
"id":469910689948389376,
"id_str":"469910689948389376",
"text":"Foto: Discorsi - Scarica l'app e Partecipa http:\/\/t.co\/zqztInkl6h #BraccialettiRossi http:\/\/t.co\/JeGHPvljwn",
"source":"\u003ca href=\"http:\/\/www.apple.com\" rel=\"nofollow\"\u003eiOS\u003c\/a\u003e",
"truncated":false,
"in_reply_to_status_id":null,
"in_reply_to_status_id_str":null,
"in_reply_to_user_id":null,
"in_reply_to_user_id_str":null,
"in_reply_to_screen_name":null,
"user":{
"id":587593116,
"id_str":"587593116",
"name":"Giulia Zaytsev",
"screen_name":"giubex",
...
}

I need to extract the following information from the object:

id_str
created_at
text
user_id

There are 200 million such lines and I need to do some processing on individual objects (check if they are not null). I tried to implement the code listed here but I am a little confused.

Thanks for your help.

Community
  • 1
  • 1
AngryPanda
  • 1,261
  • 2
  • 19
  • 42

1 Answers1

0

Initialize gson first and your model class:

    GsonBuilder builder = new GsonBuilder();
    Gson gson = builder.create();

    Item item =  gson.fromJson("your_json",Item.class);
    System.out.println(item.id_str);
    System.out.println(item.user.id);

Item.java

public class Item {

    public String id_str;
    public String created_at;
    public String text;
    public User user;

    public class User{
       public long id;
    }
}
adnbsr
  • 635
  • 4
  • 13
  • I am trying to achieve this format of code: `System.out.println(((Map)((List)((Map)(TweetObject.get("data"))).get("translations")).get(0)).get("translatedText"));` – AngryPanda Mar 13 '15 at 08:44