Close() public method

Closes this stream and the underlying stream.
public Close ( ) : void
return void
Exemplo n.º 1
0
 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     UUIDConverter UUID = new UUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         try
         {
             Hashtable hashtable = queue.Dequeue();
             serializer.Serialize(jsonWriter, hashtable);
         }
         catch(Exception e)
         {
             AjaxLife.Debug("MakeJson.FromHashTable", e.Message);
         }
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
Exemplo n.º 2
0
 public static string FromObject(object obj)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     serializer.Serialize(jsonWriter, obj);
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
Exemplo n.º 3
0
 public static string FromHashtableQueue(Queue<Hashtable> queue)
 {
     StringWriter textWriter = new StringWriter();
     JsonWriter jsonWriter = new JsonWriter(textWriter);
     jsonWriter.WriteStartArray();
     JsonSerializer serializer = new JsonSerializer();
     LLUUIDConverter UUID = new LLUUIDConverter();
     serializer.Converters.Add(UUID);
     while (queue.Count > 0)
     {
         Hashtable hashtable = queue.Dequeue();
         serializer.Serialize(jsonWriter, hashtable);
     }
     jsonWriter.WriteEndArray();
     jsonWriter.Flush();
     string text = textWriter.ToString();
     jsonWriter.Close();
     textWriter.Dispose();
     return text;
 }
        internal string Serialize(IEnumerable<EventData> events)
        {
            if (events == null)
            {
                return null;
            }

            var sb = new StringBuilder();
            _writer = new JsonTextWriter(new StringWriter(sb, CultureInfo.InvariantCulture)) { CloseOutput = true };

            foreach (var e in events)
            {
                this.WriteJsonEntry(e);
            }

            // Close the writer
            _writer.Close();
            _writer = null;

            return sb.ToString();
        }
        private string GetJsonResult(int ParentID)
        {
            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.None;

            writer.WriteStartArray();

            foreach (DataRow row in GetSubCategory(ParentID).Rows)
            {
                writer.WriteStartObject();
                WriteJsonKeyValue(writer, "catename", row["catename"].ToString());
                WriteJsonKeyValue(writer, "cateid", row["cateid"].ToString());
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }
        public string GetJsonData()
        {
            StringBuilder sb = new StringBuilder(100);
            StringWriter sw = new StringWriter(sb);
            JsonWriter js = new JsonWriter(sw);
            js.WriteStartObject();

            if (spOrderProduct != null)
            {
                js.WritePropertyName("opnum");
                js.WriteValue(spOrderProduct.Quantity);
                js.WritePropertyName("opsum");
                js.WriteValue(spOrderProduct.ProductSum);
                js.WritePropertyName("opscore");
                js.WriteValue(spOrderProduct.TotalScore);
            }
            js.WritePropertyName("carttsum");
            js.WriteValue(spCart.TotalSum);
            js.WritePropertyName("cartpsum");
            js.WriteValue(spCart.ProductSum);
            js.WriteEndObject();
            js.Close();
            return sb.ToString();
        }
Exemplo n.º 7
0
    void OnGUI()
    {
        Type targetType;
        charScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Character/Character.cs");
        if (jsonSerializer == null)
        {
            Start();
        }
        targetType = charScript.GetClass();
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("id: ", database.Count.ToString());

        if (reorderableList == null)
        {
            reorderableList = new ReorderableList(charAbilities, typeof(int),
                false, true, true, true);

            reorderableList.drawElementCallback =
                (Rect rect, int index, bool isActive, bool isFocused) => {
                    var element = reorderableList.list[index];
                    rect.y += 2;
                    reorderableList.list[index] = EditorGUI.IntField(
                        new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
                        (int)element);
                };
        }
        reorderableList.DoLayoutList();

        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                info.SetValue(tempChar, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempChar)));
            }
            else if (fieldType == typeof(string))
            {
                info.SetValue(tempChar, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempChar)));
            }
            else if (fieldType == typeof(float))
            {
                info.SetValue(tempChar, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempChar)));
            }
            else if (fieldType == typeof(Character.Stats)) //struct
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (tempStruct == null)
                {
                    tempStruct = new Character.Stats();
                    info.SetValue(tempChar, (Character.Stats)tempStruct);
                }

                foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
                {
                    Type fieldTypeInStruct = infoInStruct.FieldType;

                    if (fieldTypeInStruct == typeof(float))
                    {
                        infoInStruct.SetValue(tempStruct, EditorGUILayout.FloatField(infoInStruct.Name, (float)infoInStruct.GetValue(info.GetValue(tempChar)) ));
                    }
                }

                info.SetValue(tempChar, (Character.Stats)tempStruct);
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }
            else if (fieldType == typeof(TasteToStats))//object
            {
                var dirPath = new DirectoryInfo("Assets/Scripts/Character/TasteTranslation");
                FileInfo[] fileInfo = dirPath.GetFiles();
                List<string> fileNames = new List<string>();
                for (int i = 0; i < fileInfo.Length; i++)
                {
                    if (!fileInfo[i].Name.Contains("meta") && !fileInfo[i].Name.Equals("TasteToStats.cs"))
                    {
                        fileNames.Add(fileInfo[i].Name);
                    }
                }
                tasteToStats = EditorGUILayout.Popup("Ability:", tasteToStats, fileNames.ToArray());
                MonoScript derp = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Character/TasteTranslation/"+ fileNames[tasteToStats]);
                info.SetValue(tempChar, Activator.CreateInstance(derp.GetClass()));
            }
            else if (fieldType == typeof(List<int>))
            {
                info.SetValue(tempChar, charAbilities);
            }

        }

        EditorGUILayout.EndVertical();

        if (GUILayout.Button("submit"))
        {
            textWriter = new StreamWriter(Application.dataPath + itemFileName);
            jsonWriter = new JsonTextWriter(textWriter);
            database.Add(tempChar);
            String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            textWriter.Write(text);

            textWriter.Close();
            textWriter.Dispose();
            jsonWriter.Close();

            tempChar = new Character();
            tempStruct = null;
            reorderableList = null;
            charAbilities = new List<int>();
        }
    }
Exemplo n.º 8
0
    void OnGUI()
    {
        Type targetType;
        simpleFood = EditorGUILayout.Toggle("Is Simple Food", simpleFood);
        if (simpleFood)
        {
            mainIngredient = EditorGUILayout.Toggle("Is Main Ingredient", mainIngredient);
            if (mainIngredient)
            {
                itemScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Items/Food/MainIngredient.cs");
                targetType = itemScript.GetClass();
                if (tempItem == null || tempItem.GetType() != targetType)
                {
                    tempItem = new MainIngredient();
                }
            }
            else
            {
                itemScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Items/Food/Accompaniment.cs");
                targetType = itemScript.GetClass();
                if (tempItem == null || tempItem.GetType() != targetType)
                {
                    tempItem = new Accompaniment();
                }
            }
        }
        else
        {
            itemScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Items/Food/ComposedFood.cs");
            targetType = itemScript.GetClass();
            if (tempItem == null || tempItem.GetType() != targetType)
            {
                tempItem = new ComposedFood();
            }

            if (reorderableList == null)
            {
                reorderableList = new ReorderableList(listInputRecipe, typeof(int),
                    false, true, true, true);

                reorderableList.drawElementCallback =
                    (Rect rect, int index, bool isActive, bool isFocused) => {
                        var element = reorderableList.list[index];
                        rect.y += 2;
                        reorderableList.list[index] = EditorGUI.IntField(
                            new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
                            (int)element);
                    };
            }
            reorderableList.DoLayoutList();
        }

        if (jsonSerializer == null) {
            Start();
        }

        EditorGUILayout.BeginVertical(EditorStyles.helpBox);

        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                if (info.Name.Contains("id")){
                    info.SetValue(tempItem, database.Count);
                    EditorGUILayout.LabelField("ID of item", database.Count.ToString());
                }
                else
                {
                    info.SetValue(tempItem, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempItem)));
                }
            }
            else if (fieldType.IsEnum) {
                if (info.GetValue(tempItem) == null)
                    info.SetValue(tempItem, Activator.CreateInstance(fieldType));
                info.SetValue(tempItem, EditorGUILayout.EnumPopup(info.Name, (Enum)info.GetValue(tempItem)));
            }
            else if (fieldType == typeof(string))
            {
                string name = (String)info.GetValue(tempItem);
                info.SetValue(tempItem, EditorGUILayout.TextField(info.Name, name));
            }
            else if (fieldType == typeof(float))
            {
                info.SetValue(tempItem, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempItem)));
            }
            else if (fieldType.IsValueType && !fieldType.IsPrimitive && simpleFood) //struct
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (fieldType == typeof(Food.Taste))
                    tempStruct = new Food.Taste();

                foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
                {
                    Type fieldTypeInStruct = infoInStruct.FieldType;

                    if (fieldTypeInStruct == typeof(int))
                    {
                            infoInStruct.SetValue(tempStruct, EditorGUILayout.IntField(infoInStruct.Name, (int)infoInStruct.GetValue(info.GetValue(tempItem))));
                    }
                }

                if (fieldType == typeof(Food.Taste))
                {
                    info.SetValue(tempItem, (Food.Taste)tempStruct);
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }
            else if (fieldType == typeof(GameObject))//object
            {
                abilityName = EditorGUILayout.TextField(info.Name, abilityName);
            }
        }

        EditorGUILayout.EndVertical();

        if (GUILayout.Button("submit"))
        {
            textWriter = new StreamWriter(Application.dataPath + itemFileName);
            jsonWriter = new JsonTextWriter(textWriter);
            database.Add(tempItem);
            String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            textWriter.Write(text);

            textWriter.Close();
            textWriter.Dispose();
            jsonWriter.Close();

            if (!simpleFood) {
                tempRecipeStruct = new ComposedFood.recipe(listInputRecipe, tempItem.id);
                textWriter = new StreamWriter(Application.dataPath + recipesFileName);
                jsonWriter = new JsonTextWriter(textWriter);
                recipes.Add((ComposedFood.recipe)tempRecipeStruct);
                String recipeText = JsonConvert.SerializeObject(recipes, Formatting.Indented, new JsonSerializerSettings
                {
                    TypeNameHandling = TypeNameHandling.Objects,
                    TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
                });
                textWriter.Write(recipeText);

                textWriter.Close();
                textWriter.Dispose();
                jsonWriter.Close();
            }
            tempItem = null;
            tempStruct = null;
            reorderableList = null;
            listInputRecipe = new List<int>();
        }
    }
        private void GetEvaluation(HttpContext CurrentContext)
        {
            NewsEvaluationModelBll bll = new NewsEvaluationModelBll();
            int NewsID = Convert.ToInt32(CurrentContext.Request["nid"]);
            if (NewsID == 0)
            {
                CurrentContext.Response.Write(GetJsonResult(false, "参数错误!"));
                return;
            }

            DataTable dt = bll.StatisticList(NewsID);
            int Sum = 0;
            foreach (DataRow row in dt.Rows) Sum += Convert.ToInt32(row["evaluationcount"]);

            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);
            writer.Formatting = Formatting.Indented;

            writer.WriteStartObject();

            WriteJsonKeyValue(writer, "sum", Sum.ToString());

            writer.WritePropertyName("items");
            writer.WriteStartArray();
            foreach (DataRow row in dt.Rows)
            {
                writer.WriteStartObject();

                WriteJsonKeyValue(writer, "evaluation", row["evaluation"].ToString());
                WriteJsonKeyValue(writer, "count", row["evaluationcount"].ToString());
                WriteJsonKeyValue(writer, "percentage", Sum == 0 ? "0" : Convert.ToDouble((Convert.ToInt32(row["evaluationcount"]) * 100) / Sum).ToString("00"));

                writer.WriteEndObject();
            }
            writer.WriteEndArray();
            writer.WriteEndObject();
            writer.Close();
            CurrentContext.Response.Write("("+result.ToString()+")");
        }
        private void GetCommentList(HttpContext CurrentContext)
        {
            CommentBll bll = new CommentBll();
            int NewsID = Convert.ToInt32(CurrentContext.Request["nid"]);
            if (NewsID == 0)
            {
                CurrentContext.Response.Write(GetJsonResult(false, "参数错误!"));
                return;
            }

            DataTable dt = bll.GetList(AppType.News, NewsID);

            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);
            writer.Formatting = Formatting.Indented;
            writer.WriteStartArray();
            foreach (DataRow row in dt.Rows)
            {
                writer.WriteStartObject();

                WriteJsonKeyValue(writer, "userid", row["userid"].ToString());
                WriteJsonKeyValue(writer, "content", row["content"].ToString());
                WriteJsonKeyValue(writer, "createtime", Convert.ToDateTime(row["createtime"]).ToString("yyyy-MM-dd HH:mm:ss"));

                writer.WriteEndObject();
            }
            writer.WriteEndArray();
            writer.Close();

            CurrentContext.Response.Write("(" + result.ToString() + ")");
        }
Exemplo n.º 11
0
    void OnGUI()
    {
        Type targetType;

        if (jsonSerializer == null)
        {
            Start();
        }

        var dirPath = new DirectoryInfo("Assets/Scripts/Abilities/");
        FileInfo[] fileInfo = dirPath.GetFiles();
        List<string> fileNames = new List<string>();
        for(int i = 0; i < fileInfo.Length; i++)
        {
            if (!fileInfo[i].Name.Contains("meta") && !fileInfo[i].Name.Equals("Ability.cs"))
            {
                fileNames.Add(fileInfo[i].Name);
            }
        }
        int newscript = EditorGUILayout.Popup("TasteTranslation:",chosenScript, fileNames.ToArray());
        if(newscript != chosenScript)
        {
            chosenScript = newscript;
            tempAbility = null;
        }
        abilityScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Abilities/"+ fileNames[chosenScript]);
        targetType = abilityScript.GetClass();
        if (tempAbility == null)
        {
            tempAbility = (Ability)Activator.CreateInstance(targetType);
        }
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("id: ", database.Count.ToString());
        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                info.SetValue(tempAbility, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempAbility)));

            }else if(fieldType == typeof(string))
            {
                info.SetValue(tempAbility, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempAbility)));
            }
            else if (fieldType == typeof(bool))
            {
                info.SetValue(tempAbility, EditorGUILayout.Toggle(info.Name, (bool)info.GetValue(tempAbility)));
            }
        }

        EditorGUILayout.EndVertical();

        if (GUILayout.Button("submit"))
        {
            textWriter = new StreamWriter(Application.dataPath + itemFileName);
            jsonWriter = new JsonTextWriter(textWriter);
            database.Add(tempAbility);
            String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            textWriter.Write(text);

            textWriter.Close();
            textWriter.Dispose();
            jsonWriter.Close();

            tempAbility = null;
        }
    }
Exemplo n.º 12
0
    void OnGUI()
    {
        Type targetType;
        charScript = AssetDatabase.LoadAssetAtPath<MonoScript>("Assets/Scripts/Enemies/Enemies.cs");
        if (jsonSerializer == null)
        {
            Start();
        }
        targetType = charScript.GetClass();
        EditorGUILayout.BeginVertical(EditorStyles.helpBox);
        EditorGUILayout.LabelField("id: ", database.Count.ToString());

        if (reorderableList == null)
        {
            reorderableList = new ReorderableList(charAbilities, typeof(int),
                false, true, true, true);

            reorderableList.drawElementCallback =
                (Rect rect, int index, bool isActive, bool isFocused) => {
                    var element = reorderableList.list[index];
                    rect.y += 2;
                    reorderableList.list[index] = EditorGUI.IntField(
                        new Rect(rect.x, rect.y, 60, EditorGUIUtility.singleLineHeight),
                        (int)element);
                };
        }
        reorderableList.DoLayoutList();

        foreach (FieldInfo info in targetType.GetFields(flags))
        {
            Type fieldType = info.FieldType;
            if (fieldType == typeof(int))
            {
                info.SetValue(tempEnemy, EditorGUILayout.IntField(info.Name, (int)info.GetValue(tempEnemy)));
            }
            else if (fieldType == typeof(string))
            {
                info.SetValue(tempEnemy, EditorGUILayout.TextField(info.Name, (string)info.GetValue(tempEnemy)));
            }
            else if (fieldType == typeof(float))
            {
                info.SetValue(tempEnemy, EditorGUILayout.FloatField(info.Name, (float)info.GetValue(tempEnemy)));
            }
            else if (fieldType == typeof(Enemies.EnemyStats)) //struct
            {
                EditorGUILayout.Space();
                EditorGUILayout.BeginVertical(EditorStyles.helpBox);
                if (tempStruct == null)
                {
                    tempStruct = new Enemies.EnemyStats();
                    info.SetValue(tempEnemy, (Enemies.EnemyStats)tempStruct);
                }

                foreach (FieldInfo infoInStruct in fieldType.GetFields(flags))
                {
                    Type fieldTypeInStruct = infoInStruct.FieldType;

                    if (fieldTypeInStruct == typeof(float))
                    {
                        infoInStruct.SetValue(tempStruct, EditorGUILayout.FloatField(infoInStruct.Name, (float)infoInStruct.GetValue(info.GetValue(tempEnemy)) ));
                    }
                }

                info.SetValue(tempEnemy, (Enemies.EnemyStats)tempStruct);
                EditorGUILayout.EndVertical();
                EditorGUILayout.Space();
            }
            else if (fieldType == typeof(List<int>))
            {
                info.SetValue(tempEnemy, charAbilities);
            }

        }

        EditorGUILayout.EndVertical();

        if (GUILayout.Button("submit"))
        {
            textWriter = new StreamWriter(Application.dataPath + itemFileName);
            jsonWriter = new JsonTextWriter(textWriter);
            database.Add(tempEnemy);
            String text = JsonConvert.SerializeObject(database, Formatting.Indented, new JsonSerializerSettings
            {
                TypeNameHandling = TypeNameHandling.Objects,
                TypeNameAssemblyFormat = System.Runtime.Serialization.Formatters.FormatterAssemblyStyle.Simple
            });
            textWriter.Write(text);

            textWriter.Close();
            textWriter.Dispose();
            jsonWriter.Close();

            tempEnemy = new Enemies();
            tempStruct = null;
            reorderableList = null;
            charAbilities = new List<int>();
        }
    }
        private string GetMsgList(HttpContext context)
        {
            MessageBll mbll = new MessageBll();
            string[] roles = Roles.GetRolesForUser();
            List<MessageModel> list = mbll.GetAllList(context.User.Identity.Name,roles,1);

            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.None;
            //writer.WriteStartObject();
            writer.WriteStartArray();
            foreach (MessageModel item in list)
            {
                writer.WriteStartObject();
                writer.WritePropertyName("msgid");
                writer.WriteValue(item.MsgId);
                writer.WritePropertyName("subject");
                writer.WriteValue(item.Subject);
                writer.WriteEndObject();
            }
            writer.WriteEndArray();
            //writer.WriteEndObject();
            writer.Close();
            return result.ToString();
        }
        private string GetBrandJson(int ScenceID, int CategoryID)
        {
            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.Indented;

            DataTable dt = new CategoryConditionBll().GetConditionBrandList(ScenceID, CategoryID);
            //new BrandCategoryRelationBll().GetCategoryBrandList(CategoryID);

            writer.WriteStartArray();

            foreach (DataRow row in dt.Rows)
            {
                writer.WriteStartObject();

                WriteJsonKeyValue(writer, "brandid", row["brandid"].ToString());
                WriteJsonKeyValue(writer, "brandname", row["brandname"].ToString());

                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }
        private string GetProductListJson(int ScenceID, int CategoryID,int FatherCategoryID, int BrandID, string ProductName,int OrderType)
        {
            bool HasSubCateogry;
            DataTable dt = new CategoryConditionBll().GetCategoryProductList(ScenceID, CategoryID, FatherCategoryID, BrandID, ProductName,OrderType,out HasSubCateogry);

            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.Indented;

            writer.WriteStartArray();

            foreach (DataRow row in dt.Rows)
            {
                writer.WriteStartObject();
                WriteJsonKeyValue(writer, "productid", row["productid"].ToString());
                WriteJsonKeyValue(writer, "productname", row["productname"].ToString());
                WriteJsonKeyValue(writer, "url", String.Format("/product-{0}.html", row["productid"]));
                WriteJsonKeyValue(writer, "image", ProductMainImageRule.GetMainImageUrl(row["smallimage"].ToString()));
                WriteJsonKeyValue(writer, "price", row["merchantprice"].ToString());
                WriteJsonKeyValue(writer, "categoryid", HasSubCateogry ? row["cateid"].ToString() : "0");
                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }
        private string GetCategoryJson(int ScenceID)
        {
            StringBuilder result = new StringBuilder();
            StringWriter sw = new StringWriter(result);
            JsonWriter writer = new JsonWriter(sw);

            writer.Formatting = Formatting.Indented;

            List<SolutionCategoryModel> Categories = new SolutionCategoryBll().GetModelList("senceid = " + ScenceID);

            writer.WriteStartArray();

            foreach (SolutionCategoryModel model in Categories)
            {
                writer.WriteStartObject();

                WriteJsonKeyValue(writer, "categoryid", model.CateId.ToString());
                WriteJsonKeyValue(writer, "categoryname", model.Remark);

                writer.WritePropertyName("subcates");
                writer.WriteStartArray();
                DataTable subTable = new CategoryConditionBll().GetConditionSubCategory(ScenceID, model.CateId);
                if(subTable!=null)
                    foreach (DataRow row in subTable.Rows)
                    {
                        writer.WriteStartObject();

                        WriteJsonKeyValue(writer, "categoryid", row["cateid"].ToString());
                        WriteJsonKeyValue(writer, "categoryname", row["catename"].ToString());

                        writer.WriteEndObject();
                    }
                writer.WriteEndArray();

                writer.WriteEndObject();
            }

            writer.WriteEndArray();
            writer.Close();

            return result.ToString();
        }