private async Task <IList <object> > ProduceJsonArrayAsync(JsonTokenizer tokenizer, int depth, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer) { TokenType lsq; if (TracingEnabled) { JsonToken t = NextAndGetToken(tokenizer, tokenTailBuffer, nodeTailBuffer); // pop the leading [. tokenTailBuffer.Push(t); lsq = t.Type; } else { lsq = NextAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer); } if (lsq != TokenType.LSQUARE) { // this cannot happen. throw new InvalidJsonTokenException("JSON array should start with [. " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } IList <object> list = new List <object>(); var type = PeekAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer); if (type == TokenType.RSQUARE) { // empty array JsonToken t = tokenizer.Next(); // discard the trailing ]. if (TracingEnabled) { tokenTailBuffer.Push(t); } } else { IList <object> elements = await ProduceJsonArrayElementsAsync(tokenizer, depth, tokenTailBuffer, nodeTailBuffer); var rsq = NextAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer); // discard the trailing ]. if (rsq == TokenType.RSQUARE) { // Done ((List <object>)list).AddRange(elements); } else { // ??? throw new InvalidJsonTokenException("JSON array should end with ]. " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } } IList <object> jArray = jsonTypeFactory.CreateArray(list); if (TracingEnabled) { nodeTailBuffer.Push(jArray); } //if (log.IsLoggable(Level.FINE)) { // log.fine("jArray = " + jArray); //} return(jArray); }
private string ProduceJsonString(JsonTokenizer tokenizer, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer) { string jString = null; try { JsonToken t = tokenizer.Next(); // log.warning(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> t = " + t); if (TracingEnabled) { tokenTailBuffer.Push(t); } string value = (string)t.Value; // log.warning(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> value = " + value); jString = (string)jsonTypeFactory.CreateString(value); // log.warning(">>>>>>>>>>>>>>>>>>>>>>>>>>>>> jString = " + jString); } catch (Exception e) { throw new UnknownParserException("Failed to create a String node. " + tokenTailBuffer.ToTraceString(), e, GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } if (TracingEnabled) { // ??? nodeTailBuffer.Push(jString); } return(jString); }
private object ProduceJsonNull(JsonTokenizer tokenizer, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer) { object jNull = null; try { JsonToken t = tokenizer.Next(); // Consume the "null" literal. if (TracingEnabled) { tokenTailBuffer.Push(t); } jNull = jsonTypeFactory.CreateNull(); } catch (Exception e) { throw new UnknownParserException("Failed to Create a Null node. " + tokenTailBuffer.ToTraceString(), e, GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } if (TracingEnabled) { nodeTailBuffer.Push(jNull); } return(jNull); }
private bool?ProduceJsonBoolean(JsonTokenizer tokenizer, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer) { bool?jBoolean = null; try { JsonToken t = tokenizer.Next(); if (TracingEnabled) { tokenTailBuffer.Push(t); } var value = (bool)t.Value; jBoolean = (bool?)jsonTypeFactory.CreateBoolean((bool?)value); } catch (Exception e) { throw new UnknownParserException("Failed to Create a Boolean node. " + tokenTailBuffer.ToTraceString(), e, GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } if (TracingEnabled) { nodeTailBuffer.Push(jBoolean); } return(jBoolean); }
private Number?ProduceJsonNumber(JsonTokenizer tokenizer, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer) { Number?jNumber = null; try { JsonToken t = tokenizer.Next(); if (TracingEnabled) { tokenTailBuffer.Push(t); } var value = (Number)t.Value; jNumber = (Number?)jsonTypeFactory.CreateNumber((Number?)value); } catch (Exception e) { throw new UnknownParserException("Failed to Create a Number node. " + tokenTailBuffer.ToTraceString(), e, GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } if (TracingEnabled) { nodeTailBuffer.Push(jNumber); } return(jNumber); }
private async Task <IDictionary <string, object> > ProduceJsonObjectAsync(JsonTokenizer tokenizer, int depth, JsonTokenBuffer tokenTailBuffer, ObjectTailBuffer nodeTailBuffer) { var lcurl = NextAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer); // pop the leading {. if (lcurl != TokenType.LCURLY) { // this cannot happen. throw new InvalidJsonTokenException("JSON object should start with {. " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } IDictionary <string, object> map = new Dictionary <string, object>(); var type = PeekAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer); if (type == TokenType.RCURLY) { // empty object JsonToken t = tokenizer.Next(); // discard the trailing }. if (TracingEnabled) { tokenTailBuffer.Push(t); } } else { IDictionary <string, object> members = await ProduceJsonObjectMembersAsync(tokenizer, depth, tokenTailBuffer, nodeTailBuffer); TokenType rcurl; if (TracingEnabled) { JsonToken t = NextAndGetToken(tokenizer, tokenTailBuffer, nodeTailBuffer); // discard the trailing }. tokenTailBuffer.Push(t); rcurl = t.Type; } else { rcurl = NextAndGetType(tokenizer, tokenTailBuffer, nodeTailBuffer); // discard the trailing }. } if (rcurl == TokenType.RCURLY) { // Done // ??? // (map as Dictionary<string, object>)?.putAll(members); // map = (IDictionary<string, JsonNode>) members; ???? foreach (var m in members) { map[m.Key] = m.Value; } // ??? } else { // ??? throw new InvalidJsonTokenException("JSON object should end with }. " + tokenTailBuffer.ToTraceString(), GetTailCharStream(tokenizer), PeekCharStream(tokenizer)); } } IDictionary <string, object> jObject = jsonTypeFactory.CreateObject(map); if (TracingEnabled) { nodeTailBuffer.Push(jObject); } //if (log.IsLoggable(Level.FINE)) { // log.fine("jObject = " + jObject); //} return(jObject); }