你好M使用JSON解析在我的Android應用程序。 M使用PHP進行Web服務。 M從服務器獲取微調器中的值。現在我想發回特定的微調號回到服務器如何發送請幫助我。 Thnaks如何發送微調ID到服務器使用JSON Web服務在Android
我的代碼
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();
}
}
}
是什麼orderJson在我們的代碼plz幫助我 – user2306201
「orderJson」是我要發送到服務器的內容。 'List orderJson = new ArrayList (); \t \t \t orderJson.add(new BasicNameValuePair(「order」,json)); ' 用您的微調ID替換「json」。 –