Testing Syntax HighLight

package com.arliando.mapdashboard;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.json.JSONArray;
import org.json.JSONObject;

import android.content.Context;
import android.widget.Toast;

public class RSTampilData {
	Context context;
	// akses http
	private JSONObject object;
	private String xresult;
	private String url = "http://192.168.1.2/skripsi/lokasi_rs_json.php";
	private double[] lat;
	private double[] lng;
	private String[] nama;
	private String[] alamat;

	public RSTampilData(Context context) {
		// TODO Auto-generated constructor stub
		this.context = context;
		
		xresult = getRequest(url);
	}

	public String getRequest(String url) {
		String sRet = "";

		HttpClient client = new DefaultHttpClient();
		HttpGet request = new HttpGet(url);
		try {
			HttpResponse response = client.execute(request);
			sRet = requested(response);
		} catch (Exception e) {
			// TODO: handle exception
			Toast.makeText(context, "error " + e.getMessage(),
					Toast.LENGTH_LONG).show();
		}
		return sRet;
	}

	private String requested(HttpResponse response) {
		// TODO Auto-generated method stub
		String result = "";
		try {
			InputStream in = response.getEntity().getContent();
			BufferedReader buf = new BufferedReader(new InputStreamReader(in));
			StringBuilder builder = new StringBuilder();
			String line = null;
			while ((line = buf.readLine()) != null) {
				builder.append(line + "\n");
			}
			in.close();
			result = builder.toString();
		} catch (Exception e) {
			// TODO: handle exception
			result = "errror read data";
		}
		return result;
	}
	
	public String parse() throws Exception{
		object = new JSONObject(xresult);
		
		JSONArray menuItemArray = object.getJSONArray("posisi");
		String s ="";
		
		for (int i = 0; i

0 Comments

Mari komentar dan berdiskusi...