C#簡単なjsonデータフォーマットを生成するクラス


using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace Manager
{
    class JSONHelp
    {
        //    
        private bool success;
        //      
        private string error;
        //  
        private int totalCount;
        //  
        private string singleInfo;

        private ArrayList arrData;
        #region    JSONHelp     
        public JSONHelp() 
        {
            error = string.Empty;
            singleInfo = string.Empty;
            totalCount = 0;
            success = false;
            arrData = new ArrayList();
        }
        #endregion

        #region   JSONHelp     
        public void ResetJSONHelp() 
        {
            error = string.Empty;
            singleInfo = string.Empty;
            totalCount = 0;
            success = false;
            arrData.Clear();
        }
        #endregion

        #region           
        public void addItemOk() 
        {
            arrData.Add("<br>");
        }
        #endregion

        #region       key,value
        public void addItem(string name,string value) 
        {
            arrData.Add("\"" + name + "\":" + "\"" + value + "\"");
        }
        #endregion

        #region       json   
        public override string  ToString() 
        {
            StringBuilder sb = new StringBuilder();
            sb.Append("{");
            sb.Append("\"totalCount\":\"" + this.totalCountS + "\",");
            sb.Append("\"error\":\"" + this.errorS + "\",");
            sb.Append("\"success\":\"" + this.successS + "\",");
            sb.Append("\"data\":[");

            int index = 0;
            sb.Append("{");
            if (arrData.Count <= 0)
            {
                sb.Append("}]");
            }
            else
            {
                foreach (string val in arrData)
                {
                    index++;

                    if (val != "<br>")
                    {
                        sb.Append(val + ",");
                    }
                    else
                    {
                        sb = sb.Replace(",", "", sb.Length - 1, 1);
                        sb.Append("},");
                        if (index < arrData.Count)
                        {
                            sb.Append("{");
                        }
                    }
                   
                }
                sb = sb.Replace(",", "", sb.Length - 1, 1);
                sb.Append("]");
            }
            
            sb.Append("}");
            return sb.ToString();

        }
        #endregion
        public string errorS 
        {
            get 
            {
                return this.error;
            }
            set 
            {
                this.error = value;
            }
        }

        public bool successS 
        {
            get 
            {
                return this.success;
            }
            set 
            {
                this.success = value;
            }
        }

        public int totalCountS
        {
            get 
            {
                return this.totalCount;
            }
            set 
            {
                this.totalCount = value;
            }
        } 

    }
}