Json Formatındaki veriyi parse etmek
Merhabalar arkadaşlar mysql veri tabanından json formatında çektiği veriyi android ile almak istiyorum ancak bu kodu çalıştırınca uygulama durdu hatası veriyor sebebi ne olabilir.
//json formatındaki veri bu Konum kısmını çekmek istiyorum
//[{"id":"31","Kimlik":"11040","Konum":"58916841655"}]
//Android Kodları denemeler yaptığım için kütüphaneler biraz fazla dosyayı ".pdf" olarak ekliyorum teşekkürler
package com.aslgmail.vdt.konumuygulama;
import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Entity;
import android.content.Intent;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.provider.Settings;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.TextView;
import android.widget.Toast;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
import org.apache.http.StatusLine;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.ResponseHandler;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.BasicResponseHandler;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpConnectionParams;
import org.apache.http.util.EntityUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
private String provider;
private Criteria criteria;
Button btnkonum;
TextView txtmesafe;
JSONObject json;
private static final String URL = "http://www.vedataslan.esy.es/phpcekmeislemi.php";
@SuppressLint("ResourceAsColor")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btnkonum= (Button) findViewById(R.id.btnkonum);
txtmesafe = (TextView) findViewById(R.id.txtmesafe);
// Define the criteria how to select the location provider
criteria = new Criteria();
criteria.setAccuracy(Criteria.ACCURACY_COARSE); //default
}
protected JSONObject vericekme() throws ClientProtocolException,IOException,JSONException
{
HttpClient client =new DefaultHttpClient();
HttpGet get= new HttpGet(URL);
HttpResponse response=client.execute(get);
StatusLine status =response.getStatusLine();
int s=status.getStatusCode();
if(s==200)
{
HttpEntity e=response.getEntity();
String data= EntityUtils.toString(e);
JSONArray posts=new JSONArray(data);
JSONObject last=posts.getJSONObject(0);
}
return null;
}
public class Jsonvericek extends AsyncTask<String,String ,String>
{
@Override
protected String doInBackground(String... params) {
try {
json=vericekme();
String data=json.getString(params[0]);
return data;
} catch (ClientProtocolException e) {
e.printStackTrace();
}catch (IOException e) {
e.printStackTrace();
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(String data)
{
txtmesafe.setText(data.toString());
//yazdırmakısmı
}
}
public void btnkonum(View v)
{
new Jsonvericek().execute("Konum");
}
}