Skip to content

Instantly share code, notes, and snippets.

@azec-pdx
Created January 15, 2015 18:03
Show Gist options
  • Select an option

  • Save azec-pdx/72e3e16cf0251bcd0bf2 to your computer and use it in GitHub Desktop.

Select an option

Save azec-pdx/72e3e16cf0251bcd0bf2 to your computer and use it in GitHub Desktop.
Gist za onCreate() u RESTWebService primjeru
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
setContentView(R.layout.activity_main);
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(
"http://www.cheesejedi.com/rest_services/get_big_cheese.php?puzzle=");
TextView textView = (TextView) findViewById(R.id.textView1);
try {
HttpResponse response = httpclient.execute(httppost);
String jsonResult = inputStreamToString(
response.getEntity().getContent()).toString();
JSONArray jsonArray = new JSONArray(jsonResult);
for (int i = 0; i < jsonArray.length(); i++) {
textView.append("id: "
+ jsonArray.getJSONObject(i).getString("id").toString()
+ "\n");
textView.append("level: "
+ jsonArray.getJSONObject(i).getString("level")
.toString() + "\n");
textView.append("time_in_secs: "
+ jsonArray.getJSONObject(i).getString("time_in_secs")
.toString() + "\n");
textView.append("par: "
+ jsonArray.getJSONObject(i).getString("par")
.toString() + "\n");
textView.append("initials: "
+ jsonArray.getJSONObject(i).getString("initials")
.toString() + "\n");
textView.append("quote: "
+ jsonArray.getJSONObject(i).getString("quote")
.toString() + "\n");
textView.append("time_stamp: "
+ jsonArray.getJSONObject(i).getString("time_stamp")
.toString() + "\n");
textView.append("-------------------------------------------------"
+ "\n");
}
// textView.setText(jsonResult);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment