示例#1
0
        // -----------------------------------------------------------------------------
        // Parses the string representation of a JSON object.
        protected static JObject ParseObject(string s, ref int i)
        {
            MustBeChar(s, ref i, '{');
            RemoveWhiteSpaces(s, ref i);
            if (eof(s, i))
            {
                throw new SystemException("JSON: eof seen parsing object.");
            }
            var attributes = new List <JNameValuePair>();

            while (s[i] != '}')
            {
                var nv = JNameValuePair.Decode(s, ref i);
                attributes.Add(nv);
                RemoveWhiteSpaces(s, ref i);
                if (eof(s, i))
                {
                    throw new SystemException("JSON: eof seen parsing object.");
                }
                switch (s[i])
                {
                case ',': { ++i; RemoveWhiteSpaces(s, ref i); break; }

                case '}': { break; }

                default: {
                    throw new SystemException("JSON: invalid character: " + s[i] + " used as seperator in parsing object.");
                }
                }
            }
            ++i;
            return(new JObject(attributes.ToArray()));
        }
示例#2
0
        // =============================================================================
        // Decoding functions
        // -----------------------------------------------------------------------------
        // Returns the value of an attribute from the JSON formatted string.
        protected static JValue GetValueFor(string jsonStr, string accessorStr)
        {
            int i    = 0;
            var root = JNameValuePair.Decode(jsonStr, ref i);

            i = 0;
            var attribute = ParseAttribute(accessorStr, ref i);

            if (attribute != root.name)
            {
                return(JNull.identity);
            }
            accessorStr = accessorStr.Substring(i, accessorStr.Length - i);
            return(root.value.GetValueFor(accessorStr));
        }
示例#3
0
 public JObject(JNameValuePair v1, JNameValuePair v2) : this(new JNameValuePair[]{v1,v2}) {}
示例#4
0
 public JObject(JNameValuePair v1, JNameValuePair v2, JNameValuePair v3) : this(new JNameValuePair[]{v1,v2,v3}) {}
示例#5
0
 public JObject(JNameValuePair v)       : this(new JNameValuePair[]{v}) {}