private void WriteDefaultTable()
        {
            JSONArrayCollection Face1 = new JSONArrayCollection();

            Face1.Add(CardDefinitions.newCardDef("English", "EN", false));
            Face1.Add(CardDefinitions.newCardDef("English", "EN", true));

            JSONArrayCollection Face2 = new JSONArrayCollection();

            Face2.Add(CardDefinitions.newCardDef("Pinyin", "ZH", false));
            Face2.Add(CardDefinitions.newCardDef("TradChinese", "ZH", false));
            Face2.Add(CardDefinitions.newCardDef("SimpChinese", "ZH", false));
            Face2.Add(CardDefinitions.newCardDef("TradChinese", "ZH", true));

            String strFace1 = Face1.ToString();
            String strFace2 = Face2.ToString();

            var commands = new[] {
                "CREATE TABLE CardData (" + COLUMNCardDataID + " INTEGER PRIMARY KEY, English ntext, Pinyin ntext, TradChinese ntext, SimpChinese ntext, German ntext)",
                "INSERT INTO CardData (English, Pinyin, TradChinese, SimpChinese, German) VALUES ('One', 'Yi', '一', '一', 'ein')",
                "INSERT INTO CardData (English, Pinyin, TradChinese, SimpChinese, German) VALUES ('Two', 'Er', '二', '二', 'zwei')",
                "INSERT INTO CardData (English, Pinyin, TradChinese, SimpChinese, German) VALUES ('Three', 'San', '三', '三', 'drei')",

                "CREATE TABLE CardDefinitions (" + COLUMNCardDefinitionID + " INTEGER PRIMARY KEY, FaceCardName ntext, Face1 ntext, Face2 ntext)",
                "INSERT INTO CardDefinitions (FaceCardName, Face1, Face2) VALUES ('Eng->Ch', '" + strFace1 + "', '" + strFace2 + "')",
                "INSERT INTO CardDefinitions (FaceCardName, Face1, Face2) VALUES ('Ch->Eng', '" + strFace2 + "', '" + strFace1 + "')",

                "CREATE TABLE CardOutput (" + COLUMNCardOutputID + " INTEGER PRIMARY KEY, " + COLUMNCardDefinitionID + " INTEGER, " + COLUMNCardDataID + " INTEGER)",
            };

            execDB(commands);

            //!
        }
Пример #2
0
        public static JSONArrayCollection GetJsonList <T>(IList <T> list)
        {
            if (list == null || list.Count < 1)
            {
                return(new JSONArrayCollection());
            }
            JSONArrayCollection jsonList = new JSONArrayCollection();

            foreach (object obj in list)
            {
                if (obj == null)
                {
                    continue;
                }
                Type type = obj.GetType();
                if (ObjectUtil.IsList <T>(obj))
                {
                    jsonList.Add(GetJsonList(obj as IList <T>));
                }
                else
                {
                    jsonList.Add(GetJsonObjcet(obj));
                }
            }
            return(jsonList);
        }
Пример #3
0
        private JSONValue GetJSONValue(object objValue)
        {
            JSONValue jsonValue = null;

            if (objValue != null)
            {
                Type thisType = objValue.GetType();

                if (thisType == typeof(System.Int32))
                {
                    jsonValue = new JSONNumberValue(Convert.ToInt32(objValue));
                }
                else if (thisType == typeof(System.Single))
                {
                    jsonValue = new JSONNumberValue(Convert.ToSingle(objValue));
                }
                else if (thisType == typeof(System.Double))
                {
                    jsonValue = new JSONNumberValue(Convert.ToDouble(objValue));
                }
                else if (thisType == typeof(System.Decimal))
                {
                    jsonValue = new JSONNumberValue(Convert.ToDecimal(objValue));
                }
                else if (thisType == typeof(System.Byte))
                {
                    jsonValue = new JSONNumberValue(Convert.ToByte(objValue));
                }
                else if (thisType == typeof(System.String))
                {
                    jsonValue = new JSONStringValue(Convert.ToString(objValue));
                }
                else if (thisType == typeof(System.Boolean))
                {
                    jsonValue = new JSONBoolValue(Convert.ToBoolean(objValue));
                }
                else if (thisType.BaseType == typeof(System.Enum))
                {
                    jsonValue = new JSONStringValue(Enum.GetName(thisType, objValue));
                }
                else if (thisType.IsArray)
                {
                    List <JSONValue> jsonValues = new List <JSONValue>();
                    Array            arrValue   = (Array)objValue;
                    for (int x = 0; x < arrValue.Length; x++)
                    {
                        JSONValue jsValue = this.GetJSONValue(arrValue.GetValue(x));
                        jsonValues.Add(jsValue);
                    }
                    jsonValue = new JSONArrayCollection(jsonValues);
                }
                else
                {
                    jsonValue = new JSONStringValue(objValue.ToString());
                }
            }
            return(jsonValue);
        }
Пример #4
0
        public static String JSONStringFromfaceCardStructure(List <CardDefinitions.CardDefClass> cardList)
        {
            JSONArrayCollection ret = new JSONArrayCollection();

            foreach (CardDefClass item in cardList)
            {
                ret.Add(CardDefinitions.newCardDef(item.COLUMNSOURCE, item.LANGUAGECODE, item.TYPE));
            }
            return(ret.ToString());
        }
        static string[] ToStringArray(JSONArrayCollection arrayCollection)
        {
            var pool = new string[arrayCollection.Count];

            for (int i = 0; i < arrayCollection.Count; i++)
            {
                pool[i] = arrayCollection[i].GetValue() as string;
            }

            return(pool);
        }
Пример #6
0
        public static JSONArrayCollection toJSONArrayCollection(IList list)
        {
            JSONArrayCollection jarr = new JSONArrayCollection();

            foreach (object obj in list)
            {
                if (obj == null)
                {
                    continue;
                }
                jarr.Add(new JSONReflector(obj));
            }
            return(jarr);
        }
Пример #7
0
        public void AddToList(String name, string id, string operation, int rowIndex, bool isTableRecord, string oddLineStyle, string evenLineStyle, bool useBullets)
        {
            JSONArrayCollection listItem = new JSONArrayCollection();

            listItem.Add(new JSONStringValue(id, true));
            int operationNumber = 0;

            switch (operation)
            {
            case "Append":
                operationNumber = 0;
                break;

            case "Insert":
                operationNumber = 1;
                break;

            case "Remove":
                operationNumber = 2;
                break;

            case "Refresh":
                operationNumber = 3;
                break;

            default:
                Debug.Assert(false, "unknown list operation: " + operation);
                break;
            }
            listItem.Add(new JSONNumberValue(operationNumber));
            listItem.Add(new JSONNumberValue(rowIndex));
            listItem.Add(new JSONNumberValue(isTableRecord ? 1 : 0));
            if (isTableRecord)
            {
                listItem.Add(new JSONStringValue(oddLineStyle));
                listItem.Add(new JSONStringValue(evenLineStyle));
            }
            else
            {
                listItem.Add(new JSONNumberValue(useBullets ? 1 : 0));
            }

            add(list, new JSONStringValue(name), listItem);
        }
Пример #8
0
 private JSONValue GetJSONValue <T>(object objValue)
 {
     if (objValue != null)
     {
         Type                thisType   = objValue.GetType();
         List <JSONValue>    jsonValues = new List <JSONValue>();
         List <T>            list       = (List <T>)objValue;
         JSONArrayCollection tColl      = new JSONArrayCollection();
         foreach (T value in list)
         {
             Dictionary <JSONStringValue, JSONValue> objs = new Dictionary <JSONStringValue, JSONValue>();
             Type           vType = value.GetType();
             PropertyInfo[] pis   = vType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
             foreach (PropertyInfo p in pis)
             {
                 objs.Add(new JSONStringValue(p.Name), GetJSONValue(p.GetValue(value, null)));
             }
             tColl.Add(new JSONObjectCollection(objs));
         }
         //jsonValue = new JSONObjectCollection(objs);
         return(tColl);
     }
     return(null);
 }
Пример #9
0
        private JSONValue GetJSONValue(object objValue)
        {
            if (objValue != null)
            {
                Type      thisType  = objValue.GetType();
                JSONValue jsonValue = null;

                if (thisType == typeof(System.Int32))
                {
                    jsonValue = new JSONNumberValue(Convert.ToInt32(objValue));
                }
                else if (thisType == typeof(System.Int16))
                {
                    jsonValue = new JSONNumberValue(Convert.ToInt16(objValue));
                }
                else if (thisType == typeof(System.Int64))
                {
                    jsonValue = new JSONNumberValue(Convert.ToInt64(objValue));
                }
                else if (thisType == typeof(System.Single))
                {
                    jsonValue = new JSONNumberValue(Convert.ToSingle(objValue));
                }
                else if (thisType == typeof(System.DateTime))
                {
                    jsonValue = new JSONStringValue(Convert.ToDateTime(objValue).ToString("yyyy-MM-dd HH:mm"));
                }
                else if (thisType == typeof(System.Double))
                {
                    jsonValue = new JSONNumberValue(Convert.ToDouble(objValue));
                }
                else if (thisType == typeof(System.Decimal))
                {
                    jsonValue = new JSONNumberValue(Convert.ToDecimal(objValue));
                }
                else if (thisType == typeof(System.Byte))
                {
                    jsonValue = new JSONNumberValue(Convert.ToByte(objValue));
                }
                else if (thisType == typeof(System.String))
                {
                    jsonValue = new JSONStringValue(Convert.ToString(objValue));
                }
                else if (thisType == typeof(System.Boolean))
                {
                    jsonValue = new JSONBoolValue(Convert.ToBoolean(objValue));
                }
                else if (thisType.BaseType == typeof(System.Enum))
                {
                    jsonValue = new JSONStringValue(Enum.GetName(thisType, objValue));
                }
                else if (thisType.IsArray)
                {
                    List <JSONValue> jsonValues = new List <JSONValue>();
                    Array            arrValue   = (Array)objValue;
                    for (int x = 0; x < arrValue.Length; x++)
                    {
                        JSONValue jsValue = this.GetJSONValue(arrValue.GetValue(x));
                        jsonValues.Add(jsValue);
                    }
                    jsonValue = new JSONArrayCollection(jsonValues);
                }
                else if (objValue is IList)
                {
                    List <JSONValue> jsonValues = new List <JSONValue>();
                    IList            list       = (IList)objValue;

                    JSONArrayCollection tColl = new JSONArrayCollection();
                    foreach (object value in list)
                    {
                        Dictionary <JSONStringValue, JSONValue> objs = new Dictionary <JSONStringValue, JSONValue>();
                        Type vType = value.GetType();

                        if (vType == typeof(System.String))
                        {
                            tColl.Add(new JSONStringValue(Convert.ToString(value)));
                            continue;
                        }

                        PropertyInfo[] pis = vType.GetProperties(System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.Public);
                        foreach (PropertyInfo p in pis)
                        {
                            JSONStringValue jsonParameterName  = new JSONStringValue(p.Name);
                            JSONValue       jsonParameterValue = this.GetJSONValue(p.GetValue(value, null));
                            if (jsonParameterValue != null)
                            {
                                if (jsonParameterValue != null)
                                {
                                    objs.Add(jsonParameterName, jsonParameterValue);
                                }
                            }
                        }
                        tColl.Add(new JSONObjectCollection(objs));
                    }
                    //jsonValue = new JSONObjectCollection(objs);
                    return(tColl);
                }

                else if (objValue.GetType().IsClass)
                {
                    Dictionary <JSONStringValue, JSONValue> jsonNameValuePairs = new Dictionary <JSONStringValue, JSONValue>();
                    PropertyInfo[] properties = thisType.GetProperties();
                    foreach (PropertyInfo pi in properties)
                    {
                        JSONStringValue jsonParameterName  = new JSONStringValue(pi.Name);
                        JSONValue       jsonParameterValue = this.GetJSONValue(pi.GetValue(objValue, null));


                        if (jsonParameterValue != null)
                        {
                            if (jsonParameterValue != null)
                            {
                                jsonNameValuePairs.Add(jsonParameterName, jsonParameterValue);
                            }
                        }
                    }
                    JSONObjectCollection resJson = new JSONObjectCollection(jsonNameValuePairs);
                    return(resJson);
                }
                return(jsonValue);
            }
            return(null);
        }
Пример #10
0
        /// <summary>
        /// An example implementation of JSONSharp. The location of a purveyor of fine aleas is used
        /// to show how different data types are handled when converted to JSON format at render time.
        /// </summary>
        /// <param name="args">command-line arguments; none used in this example</param>
        public static void Main(string[] args)
        {
            // Create a Dictionary of name/value pairs for the entire JSON object
            Dictionary <JSONStringValue, JSONValue> jsonNameValuePairs = new Dictionary <JSONStringValue, JSONValue>();

            // Create and add name/value pairs for business, address, city, state,
            // zipcode, latitude, longitude, covercharge and url
            JSONStringValue jsv_name_Business  = new JSONStringValue("business");
            JSONStringValue jsv_value_Business = new JSONStringValue("Tractor Tavern");

            jsonNameValuePairs.Add(jsv_name_Business, jsv_value_Business);

            JSONStringValue jsv_name_Address  = new JSONStringValue("address");
            JSONStringValue jsv_value_Address = new JSONStringValue("5213 Ballard Ave NW");

            jsonNameValuePairs.Add(jsv_name_Address, jsv_value_Address);

            JSONStringValue jsv_name_City  = new JSONStringValue("city");
            JSONStringValue jsv_value_City = new JSONStringValue("Seattle");

            jsonNameValuePairs.Add(jsv_name_City, jsv_value_City);

            JSONStringValue jsv_name_State  = new JSONStringValue("state");
            JSONStringValue jsv_value_State = new JSONStringValue("WA");

            jsonNameValuePairs.Add(jsv_name_State, jsv_value_State);

            JSONStringValue jsv_name_Zipcode  = new JSONStringValue("zipcode");
            JSONNumberValue jsv_value_Zipcode = new JSONNumberValue(98107);

            jsonNameValuePairs.Add(jsv_name_Zipcode, jsv_value_Zipcode);

            JSONStringValue jsv_name_Latitude  = new JSONStringValue("latitude");
            JSONNumberValue jsv_value_Latitude = new JSONNumberValue(47.665663);

            jsonNameValuePairs.Add(jsv_name_Latitude, jsv_value_Latitude);

            JSONStringValue jsv_name_Longitude  = new JSONStringValue("longitude");
            JSONNumberValue jsv_value_Longitude = new JSONNumberValue(-122.382343);

            jsonNameValuePairs.Add(jsv_name_Longitude, jsv_value_Longitude);

            JSONStringValue jsv_name_CoverCharge  = new JSONStringValue("covercharge");
            JSONBoolValue   jsv_value_CoverCharge = new JSONBoolValue(true);

            jsonNameValuePairs.Add(jsv_name_CoverCharge, jsv_value_CoverCharge);

            JSONStringValue jsv_name_Url  = new JSONStringValue("url");
            JSONStringValue jsv_value_Url = new JSONStringValue("http://tractortavern.citysearch.com/");

            jsonNameValuePairs.Add(jsv_name_Url, jsv_value_Url);


            // Add an array of payment methods
            JSONStringValue  jsv_name_PaymentMethods = new JSONStringValue("paymentmethods");
            List <JSONValue> listPaymentMethods      = new List <JSONValue>();

            listPaymentMethods.Add(new JSONStringValue("Cash"));
            listPaymentMethods.Add(new JSONStringValue("Visa"));
            listPaymentMethods.Add(new JSONStringValue("Mastercard"));
            listPaymentMethods.Add(new JSONStringValue("American Express"));
            JSONArrayCollection jsv_value_PaymentMethods = new JSONArrayCollection(listPaymentMethods);

            jsonNameValuePairs.Add(jsv_name_PaymentMethods, jsv_value_PaymentMethods);

            // Construct our object, passing the Dictionary of name/value pairs.  We could have
            // created our JSONObjectCollection first, then called the Add() method to populate
            // the object's internal Dictionary.
            JSONObjectCollection jsonObjectCollection = new JSONObjectCollection(jsonNameValuePairs);

            // The ToString() is the compact representation of the object's JSON output
            Console.WriteLine("JSONObjectCollection.ToString()");
            Console.WriteLine("===============================");
            Console.WriteLine(jsonObjectCollection.ToString());
            Console.WriteLine("===============================");
            Console.WriteLine();
            // PrettyPrint() is great for readability
            Console.WriteLine("JSONObjectCollection.PrettyPrint()");
            Console.WriteLine("===============================");
            Console.WriteLine(jsonObjectCollection.PrettyPrint());
            Console.WriteLine("===============================");
        }