Exemple #1
0
        /// <summary>
        /// 입력한 이름에 해당하는 하위 JValue를 가져옵니다.
        /// </summary>
        /// <param name="key">이름</param>
        /// <returns>입력한 이름에 존재하는 JValue 값.</returns>
        /// <example>
        /// <code>
        /// var x = JValue.Parse("{hello:{world:10}}");
        /// Trace.Assert(x["hello"]["world"] == 10);
        /// </code>
        /// </example>
        public JValue Get(string key)
        {
            if (Type == TypeCode.Object)
            {
                int end = startIndex + length - 1;

                int kStart = SkipWhitespaces(startIndex + 1);
                while (kStart < end)
                {
                    int kEnd   = SkipString(kStart);
                    int vStart = SkipWhitespaces(kEnd + 1);
                    int vEnd   = SkipValue(vStart);

                    kStart++; // remove quotes
                    kEnd--;   // remove quotes

                    if (key.Length == kEnd - kStart &&
                        JValueExtension.Equals(key, 0, source, kStart, key.Length))
                    {
                        return(new JValue(source, vStart, vEnd - vStart));
                    }

                    kStart = SkipWhitespaces(vEnd + 1);
                }
            }

            return(JValue.Null);
        }
Exemple #2
0
 private long AsLongActually(long defaultValue = 0)
 {
     if (IsInteger())
     {
         return(JValueExtension.Parse(source, startIndex, length, defaultValue));
     }
     else
     {
         return((long)JValueExtension.Parse(source, startIndex, length, (double)defaultValue));
     }
 }
Exemple #3
0
 private int AsIntActually(int defaultValue = 0)
 {
     if (IsInteger())
     {
         return(JValueExtension.Parse(source, startIndex, length, defaultValue));
     }
     else
     {
         return((int)JValueExtension.Parse(source, startIndex, length, (double)defaultValue));
     }
 }
Exemple #4
0
        public double AsDouble(double defaultValue = 0.0)
        {
            switch (Type)
            {
            case TypeCode.Boolean:
                return(AsBooleanActually() ? 1 : 0);

            case TypeCode.Number:
                return(AsDoubleActually(defaultValue));

            case TypeCode.String:
                return(JValueExtension.Parse(source, startIndex + 1, length - 2, defaultValue));

            default:
                return(defaultValue);
            }
        }
Exemple #5
0
 private double AsDoubleActually(double defaultValue = 0.0)
 {
     return(JValueExtension.Parse(source, startIndex, length, defaultValue));
 }
Exemple #6
0
 private float AsFloatActually(float defaultValue = 0.0f)
 {
     return(JValueExtension.Parse(source, startIndex, length, defaultValue));
 }