Hello M 在我的 android 应用程序中使用 json 解析。M 使用 php 进行 Web 服务。M 从服务器获取微调器中的值。现在我想将特定的微调器 ID 发送回服务器如何发送它,请帮助我。纳克斯
我的代码
class GetProviderName extends AsyncTask<String, Void, Boolean>
{
protected void onPreExecute()
{
// TODO Auto-generated method stub
super.onPreExecute();
pd2=ProgressDialog.show(NewSales.this, "Loading", "Please wait");
}
@Override
protected Boolean doInBackground(String... params) {
// TODO Auto-generated method stub
try
{
HttpClient httpclient = new DefaultHttpClient();
HttpGet httppost = new HttpGet(params[0]);
HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
view_rates = EntityUtils.toString(entity, HTTP.UTF_8);
System.out.println(view_rates);
JSONArray jarray=new JSONArray(view_rates);
System.out.println("Jarray Length:"+jarray.length());
if(jarray.length()==0)
{
norecord=true;
}
else
{
for(int i=0;i<jarray.length();i++)
{
JSONObject jbnew=jarray.getJSONObject(i);
int provider_id=Integer.valueOf(jbnew.getString("voucher_provider_id"));
String voucher_provider_name=jbnew.getString("voucher_provider_name");
Provider_structuer provider_dt=new Provider_structuer();
provider_dt.setProvider_id(provider_id);
provider_dt.setProvider_name(voucher_provider_name);
all_provider_val.add(provider_dt);
provider_names.add(voucher_provider_name);
//jbnew.put("voucher_provider_id", provider_shop_names.getSelectedItem().toString());
}
}
System.out.println("provider names" +provider_names.size());
System.out.println("provider nshpos" +all_provider_val.size());
return true;
}
catch(Exception e)
{
e.printStackTrace();
return false;
}
}
@Override
protected void onPostExecute(Boolean result)
{
// TODO Auto-generated method stub
super.onPostExecute(result);
pd2.dismiss();
if(result)
{
ArrayAdapter<String>myadapter=new ArrayAdapter<String>(NewSales.this,android.R.layout.simple_spinner_dropdown_item,provider_names);
provider_shop_names.setAdapter(myadapter);
}
else
{
provider_shop_names.setAdapter(null);
Toast.makeText(NewSales.this,"Sorry problem with connection.",Toast.LENGTH_LONG).show();
}
}
}