private JValue ParseNumber() { var isFloat = false; var start = pos; var ch = json[pos]; if (ch == JsonTokens.Negtive) { MovePosition(); if (!IsDigit(json[pos]) || json[pos] == JsonTokens.Digit0) { throw new ArgumentException(Messages.InvalidFormat); } } else if (ch == JsonTokens.Digit0) { if (pos < len - 1) { if (IsDigit(json[++pos])) { throw new ArgumentException(Messages.InvalidFormat); } } } while (pos < len && IsDigit(json[pos])) { ++pos; } if (pos < len && json[pos] == JsonTokens.Dot) { isFloat = true; MovePosition(); if (!IsDigit(json[pos])) { throw new ArgumentException(Messages.InvalidFormat); } } while (pos < len && IsDigit(json[pos])) { pos++; } if (pos < len && char.ToLower(json[pos]) == JsonTokens.Exp) { isFloat = true; MovePosition(); var next = json[pos]; if (IsDigit(next)) { while (pos < len && IsDigit(json[pos++])) { ; } } else if (next == JsonTokens.Plus || next == JsonTokens.Minus) { MovePosition(); if (!IsDigit(json[pos])) { throw new ArgumentException(Messages.InvalidFormat); } while (pos < len && IsDigit(json[pos++])) { ; } } else { throw new ArgumentException(Messages.InvalidFormat); } } var numStr = json.Substring(start, pos - start); JValue result; if (isFloat) { result = new JNumber(numStr, NumberType.Decimal); } else { result = new JNumber(numStr, NumberType.Integer); } return(result); }
public void SetDouble(string key, double v) { values[key] = new JNumber(v); }
public void SetDecimal(string key, decimal v) { values[key] = new JNumber(v); }
public void SetFloat(string key, float v) { values[key] = new JNumber(v); }
public void SetSByte(string key, sbyte v) { values[key] = new JNumber(v); }
public void SetUInt16(string key, ushort v) { values[key] = new JNumber(v); }
public void SetUInt64(string key, ulong v) { values[key] = new JNumber(v); }
#pragma warning disable 3001, 3002 public void SetUInt32(string key, uint v) { values[key] = new JNumber(v); }