如何使用json webservice在android中填充微调器

时间:2012-06-20 10:20:47

标签: android json android-spinner

我使用了这段代码

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有空值。

0 个答案:

没有答案