我不明白为什么我的JSON
不会出现。
Here是api文档,this是JSON源。
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);
}
}
}
这是我的Logcat。
答案 0 :(得分:0)
可能是因为 HTTPS 而不是HTTP?这只是猜测,但两种协议都不一样。
也许你也不必通过&#34; https://&#34;在开始:))
您还可以尝试以下方法:
HttpHandler http = new HttpHandler();
String jsonSrc = http.makeServiceCall("https://api.wheretheiss.at/v1/satellites/25544");
JSONObject jsonObj = new JSONObject(jsonSrc);
String value = jsonObj.getString("latitude");