我有一个通过 HttpPost 将对象发送到 api 的应用程序。我有一些样本,例如:
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("Destination", destination));
nameValuePairs.add(new BasicNameValuePair("Description", description));
nameValuePairs.add(new BasicNameValuePair("CreatorName ", myName));
在此对象中,我有一个“User”对象数组,其中包含 DisplayName 和 Phone。如何通过 HttpPost 发送该数组?服务器无法识别以下内容(其中引号被转义):
nameValuePairs.add(new BasicNameValuePair("Users", "[{"Destination":"St.Louis", "Phone":"1234"}]"));
最佳答案
最简单的方法是将数组转换为字符串(或 JSON 字符串)。然后在作为实体传递后使用您的服务器对其进行编码。
关于java - 在 Android 中使用 HttpPost 发送对象数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28358119/