Beispiel #1
0
 public void AddMember(JsonObjectMember member)
 {
     if (member != null)
     {
         string   key  = member.Key;
         JsonNode node = member.Value;
         map[key] = node;
     }
 }
        private IDictionary <string, JsonNode> ProduceJsonObjectMembers(JsonTokenizer tokenizer)
        {
            IDictionary <string, JsonNode> members = new Dictionary <string, JsonNode>();

            var type = PeekAndGetType(tokenizer);

            while (type != TokenType.RCURLY)
            {
                JsonObjectMember member = ProduceJsonObjectMember(tokenizer);
                if (member != null)
                {
                    members[member.Key] = member.Value;
                }
                type = PeekAndGetType(tokenizer);

                // "consume" the comma.
                if (parserPolicy.AllowExtraCommas)
                {
                    while (type == TokenType.COMMA)
                    {
                        tokenizer.Next();
                        type = PeekAndGetType(tokenizer);
                    }
                }
                else
                {
                    if (type == TokenType.COMMA)
                    {
                        tokenizer.Next();
                        type = PeekAndGetType(tokenizer);

                        if (parserPolicy.AllowTrailingComma)
                        {
                            // Continue.
                        }
                        else
                        {
                            // Invalid  char sequence: ",}"
                            if (type == TokenType.RCURLY)
                            {
                                throw new InvalidJsonTokenException("Syntax error: Object has a trailing comma.", GetTailCharStream(tokenizer), PeekCharStream(tokenizer));
                            }
                        }
                    }
                }
            }

            //if (log.isLoggable(Level.FINER)) {
            //    log.finer("members = " + members);
            //}
            return(members);
        }