1

WebリクエストからJSONの結果を逆シリアル化しようとしています。

これが私のコードです。

    void myButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            WebClient webClient = new WebClient();
            Uri uri = new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Specialty/ESRI_StateCityHighway_USA/MapServer/1/query?text=&geometry=&geometryType=esriGeometryPoint&inSR=&spatialRel=esriSpatialRelIntersects&relationParam=&objectIds=&where=POP1999%3E15000000&time=&returnCountOnly=true&returnIdsOnly=false&returnGeometry=false&maxAllowableOffset=&outSR=&outFields=STATE_NAME%2CMALES%2CFEMALES%2CPOP1999&f=json");
            webClient.OpenReadCompleted += new OpenReadCompletedEventHandler(webClient_OpenReadCompleted);
            webClient.OpenReadAsync(uri); 
            //RESULT {"count":4}

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message); 
        }
    }

    void webClient_OpenReadCompleted(object sender, OpenReadCompletedEventArgs e)
    {
        DataContractJsonSerializer ser = null;
        try
        {
            //countertext.Text =  DESERIALIZE COUNT HERE
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message); 
        }

    }

    public class Counter
    {
        public int count { get; set; }
    }
}

かなりシンプルなようですが、わかりません。

このコードをバックグラウンドエージェントで使用したいのですが、サードパーティのAPIであるため、バックグラウンドエージェントでArcGIS Runtime for WindowsPhoneAPIを使用できません。

4

1 に答える 1

2

問題なく逆シリアル化する必要があります。

var ser = new DataContractJsonSerializer(typeof(Counter));
Counter r = (Counter) ser.ReadObject(e.Result);

System.Diagnostics.Debug.WriteLine(r.count);  // 4
于 2012-05-22T00:36:18.880 に答える