【问题标题】:How to send array from android to dotnet webservice如何将数组从android发送到dotnet webservice
【发布时间】:2015-12-07 16:45:54
【问题描述】:

我有多个值要从 android 发送到 DotNet Webservice。

所有值都存储在数组中。

Dotnet 方法代码:

[WebMethod]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public void setApprovedEmp(string[] arrCheckedEmpIds)
{
     // Use array here.
}

Android 代码:

String[] arrIds = { "1009", "1001", "1012" }; // Array data is dynamic, not fix size
parameters.add(new BasicNameValuePair("arrCheckedEmpIds", arrIds));

【问题讨论】:

    标签: android asp.net web-services


    【解决方案1】:

    将你的参数对象序列化为 JSON,这样你会得到这样的结果:

    {
        "arrCheckedEmpIds":["1009", "1001", "1012"]
    }
    

    并通过 POST 请求将其作为请求负载发送到您的 WebMethod,内容类型和接受标头设置为“application/json”。

    【讨论】:

    • 如何将参数对象序列化为 JSON?
    • 我不知道如何在 Java/Android 中进行操作,但我相信您会在网上找到大量关于如何手动或使用库进行操作的资料。
    【解决方案2】:
    String[] arrIds = { "1009", "1001", "1012" };
    for(int i = 0 ; i <arrIds.length ; i++){
      parameters.add(new BasicNameValuePair("arrCheckedEmpIds", arrIds[i]));
    }
    

    【讨论】:

    • 它不起作用..当我试图在 Dotnet 中获取数组时,它将在数组中显示一个元素,并且第一个元素具有我从 android 发送的完整参数字符串。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-11
    相关资源
    最近更新 更多