public override JSONNode Remove(JSONNode aNode) { m_List.Remove(aNode); return(aNode); }
public static JSONNode Parse(string aJSON) { return(JSONNode.Parse(aJSON)); }
public static JSONNode Parse(string aJSON) { Stack <JSONNode> stack = new Stack <JSONNode>(); JSONNode ctx = null; int i = 0; StringBuilder Token = new StringBuilder(); string TokenName = ""; bool QuoteMode = false; bool TokenIsQuoted = false; while (i < aJSON.Length) { switch (aJSON[i]) { case '{': if (QuoteMode) { Token.Append(aJSON[i]); break; } stack.Push(new JSONObject()); if (ctx != null) { ctx.Add(TokenName, stack.Peek()); } TokenName = ""; Token.Length = 0; ctx = stack.Peek(); break; case '[': if (QuoteMode) { Token.Append(aJSON[i]); break; } stack.Push(new JSONArray()); if (ctx != null) { ctx.Add(TokenName, stack.Peek()); } TokenName = ""; Token.Length = 0; ctx = stack.Peek(); break; case '}': case ']': if (QuoteMode) { Token.Append(aJSON[i]); break; } if (stack.Count == 0) { throw new Exception("JSON Parse: Too many closing brackets"); } stack.Pop(); if (Token.Length > 0 || TokenIsQuoted) { ParseElement(ctx, Token.ToString(), TokenName, TokenIsQuoted); TokenIsQuoted = false; } TokenName = ""; Token.Length = 0; if (stack.Count > 0) { ctx = stack.Peek(); } break; case ':': if (QuoteMode) { Token.Append(aJSON[i]); break; } TokenName = Token.ToString(); Token.Length = 0; TokenIsQuoted = false; break; case '"': QuoteMode ^= true; TokenIsQuoted |= QuoteMode; break; case ',': if (QuoteMode) { Token.Append(aJSON[i]); break; } if (Token.Length > 0 || TokenIsQuoted) { ParseElement(ctx, Token.ToString(), TokenName, TokenIsQuoted); TokenIsQuoted = false; } TokenName = ""; Token.Length = 0; TokenIsQuoted = false; break; case '\r': case '\n': break; case ' ': case '\t': if (QuoteMode) { Token.Append(aJSON[i]); } break; case '\\': ++i; if (QuoteMode) { char C = aJSON[i]; switch (C) { case 't': Token.Append('\t'); break; case 'r': Token.Append('\r'); break; case 'n': Token.Append('\n'); break; case 'b': Token.Append('\b'); break; case 'f': Token.Append('\f'); break; case 'u': { string s = aJSON.Substring(i + 1, 4); Token.Append((char)int.Parse( s, System.Globalization.NumberStyles.AllowHexSpecifier)); i += 4; break; } default: Token.Append(C); break; } } break; default: Token.Append(aJSON[i]); break; } ++i; } if (QuoteMode) { throw new Exception("JSON Parse: Quotation marks seems to be messed up."); } return(ctx); }
public virtual JSONNode Remove(JSONNode aNode) { return(aNode); }
public JSONLazyCreator(JSONNode aNode, string aKey) { m_Node = aNode; m_Key = aKey; }
public JSONLazyCreator(JSONNode aNode) { m_Node = aNode; m_Key = null; }
public virtual void Add(JSONNode aItem) { Add("", aItem); }
public virtual void Add(string aKey, JSONNode aItem) { }