internal new static JObject Parse(JsonStream jsonStream) { jsonStream.MoveToNextContent(); if (!'{'.Equals(jsonStream.CurrentChar)) { throw ExceptionHelpers.MakeJsonErrorException(jsonStream); } List <KeyValuePair <string, JToken> > properties = new List <KeyValuePair <string, JToken> >(); jsonStream.Move(); jsonStream.MoveToNextContent(); if (jsonStream.IsStartOfString()) { while (true) { var prop = GetNextProperty(jsonStream); properties.Add(prop); jsonStream.MoveToNextContent(); if (','.Equals(jsonStream.CurrentChar)) { jsonStream.Move(); jsonStream.MoveToNextContent(); if (jsonStream.IsStartOfString()) { continue; } else if ('}'.Equals(jsonStream.CurrentChar)) { break; } else { throw ExceptionHelpers.MakeJsonErrorException(jsonStream); } } else if ('}'.Equals(jsonStream.CurrentChar)) { break; } else { throw ExceptionHelpers.MakeJsonErrorException(jsonStream); } } } else if (!'}'.Equals(jsonStream.CurrentChar)) { throw ExceptionHelpers.MakeJsonErrorException(jsonStream); } jsonStream.Move(); var answer = new JObject(); answer.m_items = new Dictionary <string, JToken>(properties); return(answer); }
internal new static JArray Parse(JsonStream jsonStream) { jsonStream.MoveToNextContent(); if (!'['.Equals(jsonStream.CurrentChar)) { throw ExceptionHelpers.MakeJsonErrorException(jsonStream); } jsonStream.Move(); jsonStream.MoveToNextContent(); List <JToken> values = new List <JToken>(); if (!']'.Equals(jsonStream.CurrentChar)) { while (true) { var value = JToken.Parse(jsonStream); values.Add(value); jsonStream.MoveToNextContent(); if (','.Equals(jsonStream.CurrentChar)) { jsonStream.Move(); jsonStream.MoveToNextContent(); if (']'.Equals(jsonStream.CurrentChar)) { break; } } else if (']'.Equals(jsonStream.CurrentChar)) { break; } } } jsonStream.Move(); var answer = new JArray(values); return(answer); }
private static KeyValuePair <String, JToken> GetNextProperty(JsonStream jsonStream) { var propName = jsonStream.MoveBehindStringAndGet(); jsonStream.MoveToNextContent(); if (!':'.Equals(jsonStream.CurrentChar)) { throw ExceptionHelpers.MakeJsonErrorException(jsonStream); } jsonStream.Move(); var propValue = JToken.Parse(jsonStream); return(new KeyValuePair <string, JToken>(propName, propValue)); }
protected static JToken Parse(JsonStream jsonStream) { JToken answer; var contentChar = jsonStream.MoveToNextContent(); switch (contentChar) { case '{': answer = JObject.Parse(jsonStream); break; case '[': answer = JArray.Parse(jsonStream); break; default: answer = JValue.Parse(jsonStream); break; } return(answer); }