Example #1
0
        /// <summary>
        /// 解析Json Content对象
        /// </summary>
        /// <param name="startIndex">当前解析字符索引</param>
        /// <returns>Json对象</returns>
        private JsonObject GetJsonContent(ref int startIndex)
        {
            if (_jsonCharArray[startIndex] != '{')
            {
                throw new JsonReadException(startIndex, "字符位置[" + startIndex + "]处,Json字符串解析content错");
            }
            JsonContent content = new JsonContent(startIndex);

            startIndex = SkipBlank(++startIndex);
            if (_jsonCharArray[startIndex] == '}')
            {
                startIndex++;
                return(content);
            }
            while (true)
            {
                string attrName = GetAttrName(ref startIndex);
                startIndex = SkipBlank(startIndex);
                if (_jsonCharArray[startIndex++] != ':')
                {
                    throw new JsonReadException(startIndex, "字符位置[" + startIndex + "]处,Json字符串解析content错");
                }
                JsonObject value = GetJsonObject(ref startIndex);
                content.AddJsonAttr(attrName, value);
                startIndex = SkipBlank(startIndex);
                if (_jsonCharArray[startIndex] == ',')
                {
                    startIndex = SkipBlank(++startIndex);
                    continue;
                }
                else if (_jsonCharArray[startIndex] == '}')
                {
                    break;
                }
                else
                {
                    throw new JsonReadException(startIndex, "字符位置[" + startIndex + "]处,Json字符串解析content出错");
                }
            }
            startIndex++;
            return(content);
        }