Ejemplo n.º 1
0
 public static JValue ValueOf(object obj)
 {
     if (obj is string)
     {
         return(JString.ValueOf(obj as string));
     }
     if (obj is int || obj is long)
     {
         return(JInteger.ValueOf(obj));
     }
     if (obj is float || obj is double)
     {
         return(JDouble.ValueOf(obj));
     }
     if (obj is bool)
     {
         return(JBoolean.ValueOf(obj));
     }
     if (obj is IList <object> )
     {
         return(JArray.ValueOf(obj as IList <object>));
     }
     if (obj is IList <Dictionary <string, object> > )
     {
         return(JArray.ValueOf(ToObjectList(obj as IList <Dictionary <string, object> >)));
     }
     if (obj is IDictionary <string, object> )
     {
         return(JObject.ValueOf(obj as IDictionary <string, object>));
     }
     return(null);
 }
Ejemplo n.º 2
0
        /**
         * Get JValue from string
         * @param value string
         * @return JValue
         */
        public static JValue ValueOfString(string val)
        {
            char c = val [0];

            if ('1' == c || '2' == c || '3' == c || '4' == c || '5' == c ||
                '6' == c || '7' == c || '8' == c || '9' == c || '0' == c)
            {
                return(val.IndexOf('.') < 0 ? (JValue)JInteger.ValueOf(val) : (JValue)JDouble.ValueOf(val));
            }
            else if ("true" == val || "false" == val)
            {
                return(JBoolean.ValueOf(val));
            }
            return(JString.ValueOf(val));
        }