0

我的代码有问题,我需要将此 Json httprequest 转换为异步方法,以便在 WP7 C# 应用程序中使用它,这是代码,我真的需要这方面的帮助。

它在以下语句中显示错误:

1) myReq.ContentLength = postData.Length;--> ContentLength 不包含该类型的方法

2) webresponse = (HttpWebResponse)myReq.GetResponse(); --> 是 Sync 方法,不包含在 httpresponse 方法中

3) StreamWriter stOut = new StreamWriter(myReq.GetRequestStream(), System.Text.Encoding.ASCII); --> 是 Sync 方法,不包含在 httpresponse 方法中

4) GoogleCell cell = JsonConvert.DeserializeObject(Response);--> 方法重载或缺少转换......并且转换在第 3 次错误。

  /// internal google cell info to post

    public GoogleCell GetCellInfo(string lac, string mnc, string mcc, string cellID)
    {

        HttpWebRequest myReq = (HttpWebRequest)WebRequest.Create("https://www.google.com/loc/json");
        myReq.Method = "POST";
        myReq.ContentType = "application/jsonrequest";
        string postData = "{\"cell_towers\": [{\"location_area_code\": \"" + lac + "\", \"mobile_network_code\": \"" + mnc + "\", \"cell_id\": \"" + cellID + "\", \"mobile_country_code\": \"" + mcc + "\"}], \"version\": \"1.1.0\", \"request_address\": \"true\"}";
        myReq.ContentLength = postData.Length;

        StreamWriter stOut = new StreamWriter(myReq.GetRequestStream(), System.Text.Encoding.ASCII);
        stOut.Write(postData);
        stOut.Close();

        HttpWebResponse webresponse;
        webresponse = (HttpWebResponse)myReq.GetResponse();
        Encoding enc = System.Text.Encoding.UTF8;
        StreamReader loResponseStream = new StreamReader(webresponse.GetResponseStream(), enc);

        string Response = loResponseStream.ReadToEnd();
        loResponseStream.Close();
        webresponse.Close();

        GoogleCell cell = JsonConvert.DeserializeObject(Response);
        return cell;


        }
    }
4

1 回答 1

1

转换 WCF 中的完整类仍然有错误

JsonConvert.DeserializeObject(响应);

于 2012-06-10T18:32:17.703 回答