I have a task for school where I have to authenticate to a server. Once authenticated I can collect(not sure if it's the right word) some JSON data, using:
List <NameValuePair> nvp = new ArrayList <NameValuePair>();
nvp.add(new BasicNameValuePair("username", "test")); //used to log in to the site
nvp.add(new BasicNameValuePair("password", "test"));
nvp.add(new BasicNameValuePair("request", "login"));
nvp.add(new BasicNameValuePair("request", "mctrainer"));
post.setEntity(new UrlEncodedFormEntity(nvp));
The data I collect using that code is:
[{"correctanswerPK":"155","challenge":"Hva er Areal","answer":"En klasse","choices":["Heltallstype","En klasse","Konstruktør"]},{"correctanswerPK":"149","challenge":"Hva brukes ordet private til","answer":"Innkapsling","choices":["Innkapsling","En klasse","Heltallstype"]},{"correctanswerPK":"161","challenge":"Hva er double","answer":"Flyttallstype","choices":["Exception","Flyttallstype","En metode"]}]
It's Norwegian data, but it's JSON nevertheless.
I'm currently 'displaying' this data by running a System.out.println()
, which means it appears in the console. However, the task is to make it appear in a JFrame. My understanding is that I need to use JSONArray and JSONObject to be able to do this, plus a JSONvalidator or something similar.
The problem is that I have no idea how to do that. Any chance someone could help me out?
My teacher told us jtwitter.jar v2.6.9 was a good library for doing this, but I'm not sure how to use it. Any other ideas?