Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用DataContractJsonSerializer反序列化WP7中的少量JSON_Json_Web Services_Windows Phone 7_Deserialization - Fatal编程技术网

如何使用DataContractJsonSerializer反序列化WP7中的少量JSON

如何使用DataContractJsonSerializer反序列化WP7中的少量JSON,json,web-services,windows-phone-7,deserialization,Json,Web Services,Windows Phone 7,Deserialization,我正在尝试反序列化来自web请求的JSON结果 这是我的密码 void myButton_Click(object sender, RoutedEventArgs e) { try { WebClient webClient = new WebClient(); Uri uri = new Uri("http://sampleserver1.arcgisonline.com/ArcGIS/rest/s

我正在尝试反序列化来自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; }
    }
}
看起来应该很简单,但我想不出来


我想在后台代理期间使用此代码,但我不能在后台代理期间使用ArcGIS runtime for windows Phone API,因为它是第三方API。

它应该反序列化,不会出现问题:

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

System.Diagnostics.Debug.WriteLine(r.count);  // 4