Example #1
0
        protected static JToken ParseToken(JsonReader reader)
        {
            if (reader.Token == JsonToken.Null)
            {
                return(new JNull());
            }

            if (reader.Token == JsonToken.String)
            {
                return(new JString((string)reader.Value));
            }

            if (reader.Token == JsonToken.Boolean)
            {
                return(new JBool((bool)reader.Value));
            }

            if (reader.Token == JsonToken.Int)
            {
                return(new JInt((int)reader.Value));
            }

            if (reader.Token == JsonToken.Float)
            {
                return(new JFloat((float)reader.Value));
            }

            if (reader.Token == JsonToken.Long)
            {
                return(new JLong((long)reader.Value));
            }

            if (reader.Token == JsonToken.Double)
            {
                return(new JDouble((double)reader.Value));
            }

            if (reader.Token == JsonToken.ArrayStart)
            {
                JArray array = new JArray();
                while (reader.Read())
                {
                    if (reader.Token == JsonToken.ArrayEnd)
                    {
                        break;
                    }
                    else
                    {
                        JToken item = ParseToken(reader);
                        if (item != null)
                        {
                            array.Add(item);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                return(array);
            }
            else if (reader.Token == JsonToken.ObjectStart)
            {
                JObject obj = new JObject();

                while (reader.Read())
                {
                    if (reader.Token == JsonToken.ObjectEnd)
                    {
                        break;
                    }
                    else if (reader.Token == JsonToken.PropertyName)
                    {
                        string name = (string)reader.Value;
                        if (!reader.Read())
                        {
                            break;
                        }

                        JToken item = ParseToken(reader);
                        if (item != null)
                        {
                            obj[name] = item;
                        }
                        else
                        {
                            break;
                        }
                    }
                }
                return(obj);
            }

            return(null);
        }
Example #2
0
 public virtual JArray OptArray(JArray def)
 {
     return(def);
 }