I’m trying to parse a local json file and the output is not what it’s supposed to show.
I have little experience with Json (and Gson) so I’m unclear as to what the problem is.
Here is the tweet class:
public class tweet {
String from_user;
String from_user_name;
String profile_image_url;
String text;
public tweet(){
//empty constructor
}
}
This is the class where Gson is used:
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import com.google.gson.Gson;
public class tweetfeedreader {
public static void main(String args[]) throws FileNotFoundException {
Gson gson = new Gson();
BufferedReader bufferedReader = new BufferedReader(new FileReader(
"C:/Users/LILITH/Desktop/jsonfile.json"));
tweet J_tweet = gson.fromJson(bufferedReader, tweet.class);
System.out.println(J_tweet);
}
}
Lastly, the .json file which i have saved onto a local directory:
http://search.twitter.com/search.json?q=%40android
there are no errors, but the output is:
tweet@3030d5aa
I’m uncertain as to what might be going wrong, so thanks for your guidance!
[Edit: I forgot to add that I have searched SO before and read the related posts. They may be similar but I am not having much luck in piecing the pieces together.]
Strip the results array out of that json, leaving nothing outside the []s.
Then this was just about the least I could modify the code to get it working: