cairwin cairwin - 1 month ago 10
Android Question

JSON will not show up

I don't understand why My

JSON
won't show up.

Here is the api documentation and this is the JSON source.

import android.app.ProgressDialog;
import android.net.Uri;
import android.os.AsyncTask;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.google.android.gms.appindexing.Action;
import com.google.android.gms.appindexing.AppIndex;
import com.google.android.gms.appindexing.Thing;
import com.google.android.gms.common.api.GoogleApiClient;

import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.params.BasicHttpParams;
import org.json.JSONException;
import org.json.JSONObject;

import java.io.BufferedReader;
import java.io.InputStream;
import java.net.URI;
import java.net.URISyntaxException;

import java.io.InputStreamReader;

import static com.celest.iss.whereistheiss.JSONParser.is;
import static com.celest.iss.whereistheiss.JSONParser.jobj;

public class IsstatusActivity extends AppCompatActivity {

JSONParser jsonparser = new JSONParser();
TextView tv;
String ab;
JSONObject jobj = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.isstatus);
tv = (TextView) findViewById(R.id.Coordinates);


new retrievedata().execute();

}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.

return true;
}


class retrievedata extends AsyncTask<String,String,String> {

@Override
protected String doInBackground(String... args) {
// TODO Auto-generated method stub
jobj = jsonparser.makeHttpRequest("https://api.wheretheiss.at/v1/satellites/25544");

// check your log for json response

try {
ab = jobj.getString("latitude");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return ab;
}
protected void onPostExecute(String ab){

tv.setText(ab);
}

}

}


Here is my Logcat.

Answer

Maybe because HTTPS instead of HTTP? It's just a guess but both protocols are not the same.
Maybe you also don't have to Pass the URL with the "https://" in the beginning :)

You also could try the following:

String x = new JSONObject(new HttpHandler().makeServiceCall("<your URL here>")).getString("<your String here>");