示例#1
0
文件: Parse.cs 项目: yufb12/FJSON
        public JsonObj ParseTable(SymbolTable table)
        {
            symbolTable = table;
            position    = -1;
            JsonObj jsonobj = Parse_E_Rule(null);

            return(jsonobj);
        }
示例#2
0
文件: Parse.cs 项目: yufb12/FJSON
 private JsonObj Parse_T_Rule(JsonObj pobj)
 {
     if (HasNext())
     {
         tokennext = GetNext();
         if (tokennext.Type == TokenType.LBRACE)
         {
             Forword();
             List <JsonObjItem> list   = new List <JsonObjItem>();
             JsonObj            objres = new JsonObj()
             {
                 Type = JsonValueType.ArrayItem, Value = list, Parent = pobj
             };
             JsonObjItem obj = Parse_F_Rule(objres);
             list.Add(obj);
             if (!HasNext())
             {
                 Error(3001, "Not Finish");
             }
             tokennext = GetNext();
             while (tokennext.Type == TokenType.COMMA)
             {
                 Forword();
                 obj = Parse_F_Rule(objres);
                 list.Add(obj);
                 tokennext = GetNext();
             }
             if (tokennext.Type != TokenType.RBRACE)
             {
                 Error(3002, "Not Finish");
             }
             Forword();
             tokennext = currentToken;
             OnJsonObjCreate(objres);
             return(objres);
         }
         else
         {
             if (!HasNext())
             {
                 Error(3003, "Not Finish");
             }
             Forword();
             tokennext = currentToken;
             if (tokennext.Type > 9)
             {
                 Error(3005, "Not Finish Symbol Invalid");
             }
             JsonObj jsonObj = new JsonObj()
             {
                 Type = JsonValueType.Value, Value = tokennext.ToValue(), Parent = pobj
             };
             OnJsonObjCreate(jsonObj);
             return(jsonObj);
         }
     }
     return(null);
 }
示例#3
0
文件: Parse.cs 项目: yufb12/FJSON
        public JsonObj Parse_E_Rule(JsonObj pobj)
        {
            if (HasNext())
            {
                Token token = GetNext();
                if (token.Type == TokenType.LBRACKET)
                {
                    List <JsonObj> list   = new List <JsonObj>();
                    JsonObj        objres = new JsonObj()
                    {
                        Type = JsonValueType.ArrayValue, Value = list, Parent = pobj
                    };
                    Forword();
                    JsonObj obj = Parse_T_Rule(objres);
                    list.Add(obj);
                    if (!HasNext())
                    {
                        Error(1001, "Not Finish");
                    }
                    tokennext = GetNext();
                    while (tokennext.Type == TokenType.COMMA)
                    {
                        Forword();
                        obj = Parse_T_Rule(objres);
                        list.Add(obj);
                        tokennext = GetNext();
                    }
                    if (tokennext.Type != TokenType.RBRACKET)
                    {
                        Error(1002, "Not Finish Symbol Invalid");
                    }
                    Forword();

                    OnJsonObjCreate(objres);
                    return(objres);
                }
                else
                {
                    return(Parse_T_Rule(pobj));
                }
            }
            return(null);
        }
示例#4
0
文件: JsonObj.cs 项目: yufb12/FJSON
        public void GetJsonObjList(List <JsonObj> buf)
        {
            switch (this.Type)
            {
            case JsonValueType.ArrayItem:
                List <JsonObjItem> list = Value as List <JsonObjItem>;
                for (int i = 0; i < list.Count; i++)
                {
                    JsonObjItem obj = list[i];
                    obj.GetJsonObjList(buf);
                    buf.Add(obj);
                }
                break;

            case JsonValueType.ArrayValue:
                List <JsonObj> list2 = Value as List <JsonObj>;
                for (int i = 0; i < list2.Count; i++)
                {
                    JsonObj obj = list2[i];
                    obj.GetJsonObjList(buf);
                    buf.Add(obj);
                }
                break;

            case JsonValueType.Object:
                JsonObjItem item = this as JsonObjItem;
                buf.Add(item);
                JsonObj obj2 = item.Value as JsonObj;
                obj2.GetJsonObjList(buf);
                break;

            case JsonValueType.Value:
                buf.Add(this);
                break;

            default:
                throw new Exception("type is error");
            }
        }
示例#5
0
文件: JsonObj.cs 项目: yufb12/FJSON
        public void GetJsonObjItems(List <JsonObjItem> buf)
        {
            switch (this.Type)
            {
            case JsonValueType.ArrayItem:
                List <JsonObjItem> list = Value as List <JsonObjItem>;
                for (int i = 0; i < list.Count; i++)
                {
                    JsonObjItem obj = list[i];
                    obj.GetJsonObjItems(buf);
                }
                break;

            case JsonValueType.ArrayValue:
                List <JsonObj> list2 = Value as List <JsonObj>;
                for (int i = 0; i < list2.Count; i++)
                {
                    JsonObj obj = list2[i];
                    obj.GetJsonObjItems(buf);
                }
                break;

            case JsonValueType.Object:
                JsonObjItem item = this as JsonObjItem;
                JsonObj     obj2 = item.Value as JsonObj;
                obj2.GetJsonObjItems(buf);
                //if (obj2.Type == JsonValueType.Value)
                //{
                buf.Add(item);
                //}
                break;

            case JsonValueType.Value:
                break;

            default:
                break;
            }
        }
示例#6
0
文件: JsonObj.cs 项目: yufb12/FJSON
        public void ToJson(System.Text.StringBuilder sb)
        {
            switch (this.Type)
            {
            case JsonValueType.ArrayItem:
                sb.Append("{");
                List <JsonObjItem> list = Value as List <JsonObjItem>;
                for (int i = 0; i < list.Count; i++)
                {
                    JsonObjItem obj = list[i];
                    obj.ToJson(sb);
                    if (i != list.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("}");
                break;

            case JsonValueType.ArrayValue:
                sb.Append("[");
                List <JsonObj> list2 = Value as List <JsonObj>;
                for (int i = 0; i < list2.Count; i++)
                {
                    JsonObj obj = list2[i];
                    obj.ToJson(sb);
                    if (i != list2.Count - 1)
                    {
                        sb.Append(",");
                    }
                }
                sb.Append("]");
                break;

            case JsonValueType.Object:
                JsonObjItem item = this as JsonObjItem;
                sb.Append("\"");
                sb.Append(item.Key);
                sb.Append("\"");
                sb.Append(":");
                JsonObj obj2 = item.Value as JsonObj;
                obj2.ToJson(sb);
                break;

            case JsonValueType.Value:
                if (Value == null)
                {
                    sb.Append("null");
                }
                else if (Value.Equals(true))
                {
                    sb.Append("true");
                }
                else if (Value.Equals(false))
                {
                    sb.Append("false");
                }
                else if (Value is string)
                {
                    sb.Append("\"");
                    sb.Append(Value.ToString());
                    sb.Append("\"");
                }
                else if (Value is decimal)
                {
                    sb.Append(Value.ToString());
                }
                else
                {
                    throw new Exception("type error");
                }
                break;

            default:
                throw new Exception("type is error");
            }
        }