Пример #1
0
		/// <summary>
		/// Deserialzes from ajax XML.
		/// </summary>
		/// <param name="n">The n.</param>
		/// <returns></returns>
		internal static IJavaScriptObject DeserialzeFromAjaxXml(XmlNode n)
		{
			switch (n.Name)
			{
				case "array":

					JavaScriptArray a = new JavaScriptArray();

					foreach (XmlNode item in n.ChildNodes)
						a.Add(DeserialzeFromAjaxXml(item));

					return a;

				case "boolean":

					JavaScriptBoolean b = new JavaScriptBoolean(n.InnerText == "true");
					return b;

				case "number":

					JavaScriptNumber i = new JavaScriptNumber();
					i.Append(n.InnerText);

					return i;

				case "string":

					JavaScriptString s = new JavaScriptString();
					s.Append(n.InnerText);

					return s;

				case "object":

					JavaScriptObject o = new JavaScriptObject();

					foreach (XmlNode p in n.SelectNodes("property"))
					{
						if (p.Attributes["name"] == null || p.ChildNodes.Count != 1)
							continue;

                        o.AddInternal(p.Attributes["name"].Value, DeserialzeFromAjaxXml(p.ChildNodes[0]));
					}

					return o;
			}

			return null;
		}
Пример #2
0
        /// <summary>
        /// Read a string object from the JSON string.
        /// </summary>
        /// <returns>Returns the string.</returns>
        internal JavaScriptString ReadString()
        {
            JavaScriptString s = new JavaScriptString();

            if (_ch == JSON_STRING_DOUBLE_QUOTE)
            {
                while (ReadNext())
                {
                    if (_ch == JSON_STRING_DOUBLE_QUOTE)
                    {
                        ReadNext();
                        return s;
                    }
                    else if (_ch == '\\')
                    {
                        ReadNext();
                        switch (_ch)
                        {
                            case 'n': s += '\n'; break;
                            case 'r': s += '\r'; break;
                            case 'b': s += '\b'; break;
                            case 'f': s += '\f'; break;
                            case 't': s += '\t'; break;
                            case '\\': s += '\\'; break;

                            case 'u':
                                string u = "";
                                for (int i = 0; i < 4; i++)
                                {
                                    // TODO: add more checks if correct format \\u0000
                                    ReadNext();
                                    u += _ch;
                                }

                                s += (char)((ushort)int.Parse(u, NumberStyles.HexNumber, CultureInfo.InvariantCulture));

                                break;

                            default:
                                s += _ch;
                                break;
                        }
                    }
                    else
                    {
                        s += _ch;
                    }
                }
            }
            else
            {
                throw new NotSupportedException("The string could not be read.");
            }

            return s;
        }
Пример #3
0
        /// <summary>
        /// Read a string object from the JSON string.
        /// </summary>
        /// <returns>Returns the string.</returns>
        internal JavaScriptString ReadString()
        {
            JavaScriptString s = new JavaScriptString();

            if (_ch == JSON_STRING_DOUBLE_QUOTE)
            {
                while (ReadNext())
                {
                    if (_ch == JSON_STRING_DOUBLE_QUOTE)
                    {
                        ReadNext();
                        return(s);
                    }
                    else if (_ch == '\\')
                    {
                        ReadNext();
                        switch (_ch)
                        {
                        case 'n': s += '\n'; break;

                        case 'r': s += '\r'; break;

                        case 'b': s += '\b'; break;

                        case 'f': s += '\f'; break;

                        case 't': s += '\t'; break;

                        case '\\': s += '\\'; break;

                        case 'u':
                            string u = "";
                            for (int i = 0; i < 4; i++)
                            {
                                // TODO: add more checks if correct format \\u0000
                                ReadNext();
                                u += _ch;
                            }

                            s += (char)((ushort)int.Parse(u, NumberStyles.HexNumber, CultureInfo.InvariantCulture));

                            break;

                        default:
                            s += _ch;
                            break;
                        }
                    }
                    else
                    {
                        s += _ch;
                    }
                }
            }
            else
            {
                throw new NotSupportedException("The string could not be read.");
            }

            return(s);
        }
Пример #4
0
        /// <summary>
        /// Reads the java script object.
        /// </summary>
        /// <returns></returns>
        internal JavaScriptString ReadJavaScriptObject()
        {
            JavaScriptString n = new JavaScriptString();

            int b = 0;
            bool bf = false;

            while (_ch != END_OF_STRING)
            {
                if (_ch == '(')
                {
                    b++;
                    bf = true;
                }
                else
                    if (_ch == ')') b--;

                if (bf)
                {

                }

                n += _ch;

                ReadNext();

                if (bf && b == 0)
                    break;

            }

            return n;
        }