我试图通过使用volley的wunderground JSON数据获取天气信息,问题是他没有显示任何数据,字符串和int,当我进行调试时我从url获得响应但没有信息显示
package imo.meteoiraq;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
RequestQueue rq;
TextView humdityDesc;
String humdity;
String url="http://api.wunderground.com/api/XXXXX/conditions/forecast/forecast10day/hourly/lang:AR/q/33.237575299999996,44.3384822.json";
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
rq= Volley.newRequestQueue(this);
humdityDesc= (TextView) findViewById(R.id.humdid);
sendjsonrequest();
}
public void sendjsonrequest(){
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject stationsJO = response.getJSONObject("current_observation");
humdity = stationsJO.getString("weather");
humdityDesc.setText(humdity);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
rq.add(jsonObjectRequest);
}
private String getDate(long timeStamp){
try{
DateFormat sdf = new SimpleDateFormat("MM/dd/yyyy hh:mm:ss");
Date netDate = (new Date(timeStamp));
return sdf.format(netDate);
}
catch(Exception ex){
return "xx";
}
}
}