如何在android中使用多部分实体向php服务器发送JSONArray字符串

如何在android中使用多部分实体向php服务器发送JSONArray字符串,php,android,multipartentity,Php,Android,Multipartentity,我无法在android中使用多部分实体将JSONArray字符串发送到php服务器。我尝试了以下操作,但不起作用: MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,BOUNDARY,Charset.defaultCharset()); entity.addPart("invite_friend", new StringBody(friendsArray)); 在PHP服务器端,它

我无法在android中使用多部分实体将JSONArray字符串发送到php服务器。我尝试了以下操作,但不起作用:

MultipartEntity entity = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE,BOUNDARY,Charset.defaultCharset());
entity.addPart("invite_friend", new StringBody(friendsArray));
在PHP服务器端,它应该是这样的:

'invite_friend' => array
    (
        0 => '800'
        1 => '794'
    )

可以做什么,请提供建议。

您可以这样做

// Prepare Category Array
for (String mFrndsID : friendsArray) {
    reqEntity.addPart("invite_friend[]", new StringBody(mFrndsID));
}
只需将[]与数组标记和paas值一起添加到循环中即可。 这里的invite\u friend是数组标记。您可以使用loop在该标记中传递值。它将作为一个数组发布到服务器上

有关更多详细信息,请参阅此答案


这可能有助于您尝试将多个值对发送到服务器端脚本的代码

String strUrl = "http://****/****.php";
url = new URL(strUrl);

HttpURLConnection connection = (HttpURLConnection) url
        .openConnection();
connection.setRequestMethod("POST");
connection.setDoOutput(true);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(
        connection.getOutputStream());

outputStreamWriter.write("user_names_giver=" +user_names_giver + "&tcredit="+tcredit+"&user_name_receiver="+user_name_receiver);                
outputStreamWriter.flush();
outputStreamWriter.close();

InputStream iStream = connection.getInputStream();
BufferedReader reader = new BufferedReader(new
InputStreamReader(iStream));

StringBuffer sb = new StringBuffer();

String line = "";

while( (line = reader.readLine()) != null)
{
    sb.append(line);
}

reader.close();
iStream.close();

这不是一个
JSONArray
请参考以下答案:“friendsArray”在字符串-值对中包含类似[“800”,“794”]:“invite_-friend”:[“800”,“794”]。如何使用Multipart发送此“[“800”,“794”]”数据。它是
StringArray
…而不是
JSONArray
。。