Example #1
0
 public static decimal DeserializeDecimal(BufferedTextReader sr, ref int nextToken)
 {
     if (nextToken == '"')
     {
         sr.InitBuffer();
         sr.FillUntil('"');
         nextToken = sr.Read(2);
         try
         {
             return sr.BufferToValue(ConvertToDecimal);
         }
         catch (Exception ex)
         {
             throw new SerializationException("Error parsing decimal at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex);
         }
     }
     var buf = sr.SmallBuffer;
     buf[0] = (char)nextToken;
     var size = sr.ReadNumber(buf, 1) + 1;
     nextToken = sr.Read();
     try
     {
         return ConvertToDecimal(buf, size, sr);
     }
     catch (Exception ex)
     {
         throw new SerializationException("Error parsing decimal at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex);
     }
 }
Example #2
0
        public static double DeserializeDouble(BufferedTextReader sr, ref int nextToken)
        {
            if (nextToken == '"')
            {
                sr.InitBuffer();
                sr.FillUntil('"');
                nextToken = sr.Read(2);
                try
                {
                    return(sr.BufferToValue(ConvertToDouble));
                }
                catch (Exception ex)
                {
                    throw new SerializationException("Error parsing double at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex);
                }
            }
            var buf = sr.SmallBuffer;

            buf[0] = (char)nextToken;
            var size = sr.ReadNumber(buf, 1) + 1;

            nextToken = sr.Read();
            try
            {
                return(ConvertToDouble(buf, size));
            }
            catch (Exception ex)
            {
                throw new SerializationException("Error parsing double at " + JsonSerialization.PositionInStream(sr) + ". " + ex.Message, ex);
            }
        }