【发布时间】:2015-04-08 17:33:33
【问题描述】:
我正在尝试将数据从 android 应用程序发送到 asp.net web api,我有两个值来发送登录名和密码,我将它们放在 NameValuePair List 中并发送它们。这是我的代码:
DefaultHttpClient client = new DefaultHttpClient();
List<NameValuePair> nameValuePair = new ArrayList<NameValuePair>();
nameValuePair.add(new BasicNameValuePair("login", getLogin()));
nameValuePair.add(new BasicNameValuePair("password", getPassword()));
HttpPost httpPost = new HttpPost(url);
StringEntity stringEntity = new StringEntity(new GsonBuilder().create().toJson(nameValuePair));
httpPost.setEntity(stringEntity);
httpPost.setHeader("Accept", "application/json");
httpPost.setHeader("Content-type", "application/json");
httpPost.setHeader("Accept-Encoding", "gzip");
HttpResponse httpResponse = client.execute(httpPost);
如何反序列化 web api 项目中的 json? 这是我想反序列化 Json 的函数:
[AcceptVerbs("POST")]
public string login([FromBody] object data)
{
//Here I want to get the login and password values from the json.
}
【问题讨论】:
标签: json asp.net-web-api