Engines/FlatRedBallXNA/FlatRedBall/IO/HttpManager.cs
/// <summary>Does an HTTP Get, and deserializes the JSON result (assumes UTF8) with the .</summary>
Does an HTTP Get, and deserializes the JSON result (assumes UTF8) with the .
Does an HTTP Get and deserializes the JSON result ( assumes UTF8 ) with the .
public static int PerformHttpGetAsJson<T>(Uri uri, Action<T, int> action, Action<Exception, int> error)
        {
            int returnValue = PerformHttpGet(uri, (json, id) =>
            {
                try
                {
                    DataContractJsonSerializer serializer = new DataContractJsonSerializer(typeof(T));
                    byte[] bytes = Encoding.UTF8.GetBytes(json);
                    using (var stream = new MemoryStream(bytes))
                    {
                        var deserialized = serializer.ReadObject(stream);
                        action((T)deserialized, id);
                    }
                }
                catch (Exception ex)
                {
                    if (error != null) error(ex, id);
                    else throw;
                }
            }, error);
            return returnValue;
        }
public static int PerformHttpGetAsJson < T > ( Uri uri , Action < T , int > action , Action < Exception , int > error ) { int returnValue = PerformHttpGet ( uri , ( json , id ) => { try { DataContractJsonSerializer serializer = new DataContractJsonSerializer ( typeof ( T ) ) ; byte [ ] bytes = Encoding . UTF8 . GetBytes ( json ) ; using ( var stream = new MemoryStream ( bytes ) ) { var deserialized = serializer . ReadObject ( stream ) ; action ( ( T ) deserialized , id ) ; } } catch ( Exception ex ) { if ( error != null ) error ( ex , id ) ; else throw ; } } , error ) ; return returnValue ; }
Does an HTTP Get, and deserializes the JSON result (assumes UTF8) with the .
Does an HTTP Get and deserializes the JSON result ( assumes UTF8 ) with the .
uri
Uri
action
Action<T, int>
error
Action<Exception, int>