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.
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.