Sunday, 4 October 2015

json

private static String url = "http://api.geon

oncreate

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(url);

TextView textView = (TextView) findViewById(R.id.textView1);
 try {

  HttpResponse response = httpclient.execute(httppost);
  String jsonResult = inputStreamToString(response.getEntity().getContent()).toString();
  Log.e("jjsonResult",""+jsonResult);
 }catch (ClientProtocolException e) {
  e.printStackTrace();
 } catch (IOException e) {
  e.printStackTrace();
 }
}
private StringBuilder inputStreamToString(InputStream is) {
String rLine = "";
StringBuilder answer = new StringBuilder();

InputStreamReader isr = new InputStreamReader(is);

BufferedReader rd = new BufferedReader(isr);

try {
while ((rLine = rd.readLine()) != null) {
answer.append(rLine);
}
}

catch (IOException e) {
e.printStackTrace();
}
return answer;
}
}


mani:<uses-permission android:name="android.permission.INTERNET" />

No comments:

Post a Comment