这是我想通过 httpPost 和 BasicNameValuePair 发送的参数结构。有什么办法可以做到这一点。或者如果有其他方法请告诉我。[在安卓应用中]
{
page : 0
retailer: [
0:{
id = "72"
type = [ 1,2 ]
}
1:{
id = "76"
type = [ 2,4 ]
}
]
message_type : null
}
这可能会帮助你
this 用于在 namvalues 中传递字符串数组列表
public List<NameValuePair> namevalueFunction(ArrayList<String> selectedImages) {
for(int i=0;i<selectedImages.size();i++)
{
nvp.add(new BasicNameValuePair("UMI_NAME"+i,selectedImages.get(i)));
}
return nvp;
}
这用于在 namvalues 中传递字符串
public List<NameValuePair> getInviteEmailValuePair(String email) {
nvp.add(new BasicNameValuePair("invitebyemail",email));
return nvp;
}
使用以下代码在 android 中将数据作为 NameValue 对传递
public void postData() {
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://www.yoursite.com/script.php");
try {
// Add your data
//you can add all the parameters your php needs in the BasicNameValuePair.
//The first parameter refers to the name in the php field for example
// $id=$_POST['customerId']; the second parameter is the value.
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id ", "72"));
nameValuePairs.add(new BasicNameValuePair("type ", "1.2"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}}