1

我用了这段代码

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 JSONObjectjson=new JSONObject(responseBody);行有问题 这里 json 具有空值。

4

0 回答 0