我使用了这段代码
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.wisknowtech.com/hotel_jobs/country_list.php");
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String responseBody = httpclient.execute(httppost,responseHandler);
JSONObject json = new JSONObject(responseBody);
JSONArray jArray = json.getJSONArray("data");
//JSONArray jsonArray = new JSONArray(responseBody);
final String[] array_spinner = new String[jArray.length()];
final Spinner countryspiner = (Spinner) findViewById(R.id.rescountry);
ArrayAdapter<String> classNameAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item,array_spinner);
classNameAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
for (int i=0; i<jArray.length(); i++)
{
String styleValue = jArray.getJSONArray(i).getString(0);
array_spinner[i] = styleValue;
}
countryspinner.setAdapter(classNameAdapter);
}
catch (JSONException e) {
e.printStackTrace();
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
我在responseBody中获得了值bt行JSONObject
中存在问题json = new JSONObject
(responseBody);这里json有空值。