Example #1
0
        static void ReflectiveWay()
        {
            //Construct my own custom object
            Tavern tavern = new Tavern();

            tavern.Business    = "Tractor Tavern";
            tavern.Address     = "5213 Ballard Ave NW";
            tavern.City        = "Seattle";
            tavern.State       = "WA";
            tavern.Zipcode     = 98107;
            tavern.Latitude    = 47.665663;
            tavern.Longitude   = -122.382343;
            tavern.CoverCharge = true;
            tavern.Url         = "http://tractortavern.citysearch.com/";
            tavern.AddPaymentMethod(PaymentMethod.Cash);
            tavern.AddPaymentMethod(PaymentMethod.Visa);
            tavern.AddPaymentMethod(PaymentMethod.Mastercard);
            tavern.AddPaymentMethod(PaymentMethod.AmericanExpress);

            //Pass it to our static reflector, which will build
            JSONReflector jsonReflector = new JSONReflector(tavern);

            // The ToString() is the compact representation of the object's JSON output
            Console.WriteLine("JSONReflector.ToString()");
            Console.WriteLine("===============================");
            Console.WriteLine(jsonReflector.ToString());
            Console.WriteLine("===============================");
            Console.WriteLine();
            // PrettyPrint() is great for readability
            Console.WriteLine("JSONReflector.PrettyPrint()");
            Console.WriteLine("===============================");
            Console.WriteLine(jsonReflector.PrettyPrint());
            Console.WriteLine("===============================");
        }
Example #2
0
 LuaValue dbgToJSON(LuaValue[] arg)
 {
     if (arg.Length > 0)
     {
         return(new LuaString(JSONReflector.ObjectToJSON(arg[0].Value)));
     }
     return(LuaNil.Nil);
 }
Example #3
0
        public static JSONValue GetJsonObjcet(object obj)
        {
            if (obj == null)
            {
                return(new JSONObjectCollection());
            }
            Type      type      = obj.GetType();
            JSONValue jsonValue = new JSONObjectCollection();

            if (ObjectUtil.IsDictionary <string, object>(obj))
            {
                /*
                 * Dictionary<string, object> dict = obj as Dictionary<string, object>;
                 * JSONObjectCollection jsonObject = new JSONObjectCollection();
                 * foreach (string key in dict.Keys)
                 * {
                 *  object temp = dict[key];
                 *  if (temp == null) continue;
                 *  if (ObjectUtil.IsList(obj))
                 *  {
                 *      jsonObject.Add(new JSONStringValue(key), GetJsonList(temp as IList));
                 *  }
                 *  else
                 *  {
                 *      jsonObject.Add(new JSONStringValue(key), GetJsonObjcet(temp));
                 *  }
                 * }
                 * jsonValue = jsonObject;
                 */
            }
            else
            {
                JSONReflector jsonRef = new JSONReflector(obj);
                jsonValue = jsonRef;
            }
            return(jsonValue);
        }