C# Windows Phone 8 HttpClient和发布JSON

C# Windows Phone 8 HttpClient和发布JSON,c#,json,windows-phone-8,dotnet-httpclient,C#,Json,Windows Phone 8,Dotnet Httpclient,一般来说,我对C#和WP8都是新手。目前,我发现在做一个简单的发布到web服务和检索答案时存在困难。所有这些都是通过JSON完成的 到目前为止,我设法写了以下内容: public async static Task<string> SendJSONData(string urlToCall, string JSONData) { HttpClient client = new HttpClient(); try {

一般来说,我对C#和WP8都是新手。目前,我发现在做一个简单的发布到web服务和检索答案时存在困难。所有这些都是通过JSON完成的

到目前为止,我设法写了以下内容:

   public async static Task<string> SendJSONData(string urlToCall, string JSONData)
    {
        HttpClient client = new HttpClient();
        try
        {

            HttpResponseMessage response = await client.PostAsync(urlToCall, new StringContent(JSONData.ToString(),Encoding.UTF8,"application/json"));
            string res = response.Content.ReadAsStringAsync().Result;
            return res;

        }
        catch
        {
            // error catching...
        }
public异步静态任务SendJSONData(字符串urlToCall,字符串JSONData)
{
HttpClient=新的HttpClient();
尝试
{
HttpResponseMessage response=wait client.postsync(urlToCall,新的StringContent(JSONData.ToString(),Encoding.UTF8,“application/json”);
string res=response.Content.ReadAsStringAsync().Result;
返回res;
}
抓住
{
//捕获错误。。。
}
但很明显,运气不好,而且我很确定运气不好。因此,我无法找到任何关于这方面的适当文件

事实上,我不确定它是否以正确的方式发送帖子,我从“return res”中得到的是:System.Threading.Tasks.Task`1[System.String]

如上所述的想法是发送一个JSON数组并从同一URL检索一个


谢谢大家的帮助!

试试
string res=wait response.Content.ReadAsStringAsync();