示例#1
0
        /// <exception cref="OutOfMemoryException"></exception>
        /// <exception cref="IOException"></exception>
        /// <exception cref="JsonReaderException"></exception>
        /// <exception cref="NotSupportedException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        /// <exception cref="System.Security.SecurityException"></exception>
        /// <exception cref="UriFormatException"></exception>
        /// <exception cref="ArgumentException"></exception>
        /// <exception cref="InvalidOperationException"></exception>
        /// <exception cref="ProtocolViolationException"></exception>
        /// <exception cref="WebException"></exception>
        /// <exception cref="ObjectDisposedException"></exception>
        /// <exception cref="ArgumentNullException"></exception>
        private static List <T> DeserializeToList <T>(JObject jObject)
        {
            try
            {
                // if we get any other error from cryptowatch
                foreach (var responseType in jObject)
                {
                    if (responseType.Key == "error")
                    {
                        throw new Exception("Cryptowatch error: " + responseType.Value.ToObject <string>());
                    }
                }
                // get JSON result objects into a list
                List <JToken> jTokens = jObject["result"].Children().ToList();
                allowance = jObject["allowance"].ToObject <Allowance>();

                // serialize JSON results into .NET objects
                List <T> objects = new List <T>();
                foreach (JToken jToken in jTokens)
                {
                    // JToken.ToObject is a helper method that uses JsonSerializer internally
                    objects.Add(jToken.ToObject <T>());
                }
                return(objects);
            }
            catch
            {
                throw;
            }
        }
示例#2
0
 /// <exception cref="OutOfMemoryException"></exception>
 /// <exception cref="IOException"></exception>
 /// <exception cref="JsonReaderException"></exception>
 /// <exception cref="NotSupportedException"></exception>
 /// <exception cref="ArgumentNullException"></exception>
 /// <exception cref="System.Security.SecurityException"></exception>
 /// <exception cref="UriFormatException"></exception>
 /// <exception cref="ArgumentException"></exception>
 /// <exception cref="InvalidOperationException"></exception>
 /// <exception cref="ProtocolViolationException"></exception>
 /// <exception cref="WebException"></exception>
 /// <exception cref="ObjectDisposedException"></exception>
 private static T Deserialize <T>(JObject jObject)
 {
     try
     {
         // if we get any other error from cryptowatch
         foreach (var responseType in jObject)
         {
             if (responseType.Key == "error")
             {
                 throw new Exception("Cryptowatch error: " + responseType.Value.ToObject <string>());
             }
         }
         allowance = jObject["allowance"].ToObject <Allowance>();
         return(jObject["result"].ToObject <T>());
     }
     catch
     {
         throw;
     }
 }