示例#1
0
 private static DynValue ParseJsonValue(Lexer L, Script script)
 {
     if (L.Current.Type == TokenType.Brk_Open_Curly)
     {
         Table t = ParseJsonObject(L, script);
         return(DynValue.NewTable(t));
     }
     else if (L.Current.Type == TokenType.Brk_Open_Square)
     {
         Table t = ParseJsonArray(L, script);
         return(DynValue.NewTable(t));
     }
     else if (L.Current.Type == TokenType.String)
     {
         return(DynValue.NewString(L.Current.Text));
     }
     else if (L.Current.Type == TokenType.Number)
     {
         return(DynValue.NewNumber(L.Current.GetNumberValue()).AsReadOnly());
     }
     else if (L.Current.Type == TokenType.True)
     {
         return(DynValue.True);
     }
     else if (L.Current.Type == TokenType.False)
     {
         return(DynValue.False);
     }
     else if (L.Current.Type == TokenType.Name && L.Current.Text == "null")
     {
         return(JsonNull.Create());
     }
     else
     {
         throw new SyntaxErrorException(L.Current, "Unexpected token : '{0}'", L.Current.Text);
     }
 }
示例#2
0
        /// <summary>
        /// Converts a generic object to JSON
        /// </summary>
        public static string ObjectToJson(object obj)
        {
            DynValue v = ObjectValueConverter.SerializeObjectToDynValue(null, obj, JsonNull.Create());

            return(JsonTableConverter.TableToJson(v.Table));
        }