当前位置: 首页>>代码示例>>C#>>正文


C# JsonReader.ReadString方法代码示例

本文整理汇总了C#中JsonReader.ReadString方法的典型用法代码示例。如果您正苦于以下问题:C# JsonReader.ReadString方法的具体用法?C# JsonReader.ReadString怎么用?C# JsonReader.ReadString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在JsonReader的用法示例。


在下文中一共展示了JsonReader.ReadString方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: JsonDeserializer

    // Reader
    public static object JsonDeserializer(JsonReader reader)
    {
        var scoreEntry = new RankEntry();

        reader.ReadArrayStart();
        scoreEntry.rankIndex = (int)reader.ReadNumber();
        scoreEntry.accountId = reader.ReadString();
        scoreEntry.name = reader.ReadString();
        scoreEntry.country = reader.ReadString();
        scoreEntry.bestRanking = (int)reader.ReadNumber();
        scoreEntry.totalDamage = (long)reader.ReadNumber();
        reader.ReadArrayEnd();

        return scoreEntry;
    }
开发者ID:judah4,项目名称:battle-of-mages,代码行数:16,代码来源:RankEntry.cs

示例2: ImportValue

        protected override object ImportValue(ImportContext context, JsonReader reader)
        {
            string s = reader.ReadString().Trim();
        
            if (s.Length > 0)
            {
                char ch = s[0];
            
                if (Char.IsDigit(ch) || ch == '+' || ch == '-')
                    throw Error(s, null);
            }

            try
            {
                return Enum.Parse(OutputType, s, true);
            }
            catch (ArgumentException e)
            {
                //
                // Value is either an empty string ("") or only contains 
                // white space. Value is a name, but not one of the named
                // constants defined for the enumeration.
                //
            
                throw Error(s, e);
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:27,代码来源:EnumImporter.cs

示例3: ImportFromString

 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     try
     {
         return Convert.FromBase64String(reader.ReadString());
     }
     catch (FormatException e)
     {
         throw new JsonException("Error converting JSON String containing base64-encode data to " + OutputType.FullName + ".", e);
     }
 }
开发者ID:liuxing7954,项目名称:cangku_1,代码行数:11,代码来源:ByteArrayImporter.cs

示例4: Import

        public override object Import(ImportContext context, JsonReader reader)
        {
            if (reader == null)
                throw new ArgumentNullException("reader");

            reader.MoveToContent();
            
            if (reader.TokenClass == JsonTokenClass.String)
            {
                return reader.ReadString();
            }
            else if (reader.TokenClass == JsonTokenClass.Number)
            {
                return reader.ReadNumber();
            }
            else if (reader.TokenClass == JsonTokenClass.Boolean)
            {
                return reader.ReadBoolean();
            }
            else if (reader.TokenClass == JsonTokenClass.Null)
            {
                reader.Read();
                return null;
            }
            else if (reader.TokenClass == JsonTokenClass.Array)
            {
                JsonArray items = new JsonArray();
                items.Import(context, reader);
                return items;
            }
            else if (reader.TokenClass == JsonTokenClass.Object)
            {
                JsonObject o = new JsonObject();
                o.Import(context, reader);
                return o;
            }
            else 
            {
                throw new JsonException(string.Format("{0} not expected.", reader.TokenClass));
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:41,代码来源:AutoImporter.cs

示例5: DecodeArrayForm

        /// <summary>
        /// Converts JsonML in array form to XML.
        /// </summary>
        
        public static void DecodeArrayForm(JsonReader reader, XmlWriter writer)
        {
            if (reader == null) throw new ArgumentNullException("reader");
            if (writer == null) throw new ArgumentNullException("writer");

            reader.ReadToken(JsonTokenClass.Array);

            if (reader.TokenClass == JsonTokenClass.EndArray)
            {
                if (writer.WriteState != WriteState.Element && writer.WriteState != WriteState.Content)
                    throw new JsonMLException("Missing root element.");
            }
            else
            {
                writer.WriteStartElement(reader.ReadString());

                //
                // If there is a second element that is a JSON object then
                // it represents the element attributes.
                //

                if (reader.TokenClass == JsonTokenClass.Object)
                {
                    reader.Read();

                    while (reader.TokenClass != JsonTokenClass.EndObject)
                    {
                        string name = reader.ReadMember();

                        if (reader.TokenClass == JsonTokenClass.Object ||
                            reader.TokenClass == JsonTokenClass.Array)
                        {
                            throw new JsonMLException(
                                "Attribute value cannot be structural, such as a JSON object or array.");
                        }

                        writer.WriteAttributeString(name,
                            reader.TokenClass == JsonTokenClass.Null ?
                                string.Empty : reader.Text);

                        reader.Read();
                    }

                    reader.Read();
                }

                //
                // Process any remaining elements as child elements
                // and text content.
                //

                while (reader.TokenClass != JsonTokenClass.EndArray)
                {
                    if (reader.TokenClass == JsonTokenClass.Object)
                    {
                        throw new JsonMLException(
                            "Found JSON object when expecting " +
                            "either a JSON array representing a child element " +
                            "or a JSON string representing text content.");
                    }

                    if (reader.TokenClass == JsonTokenClass.Array)
                    {
                        Decode(reader, writer);
                    }
                    else if (reader.TokenClass == JsonTokenClass.Null)
                    {
                        reader.Read();
                    }
                    else
                    {
                        writer.WriteString(reader.Text);
                        reader.Read();
                    }
                }

                writer.WriteEndElement();
            }

            reader.Read();
        }
开发者ID:db48x,项目名称:KeeFox,代码行数:85,代码来源:JsonMLCodec.cs

示例6: ImportFromString

 protected override object ImportFromString(ImportContext context, JsonReader reader)
 {
     return reader.ReadString();
 }
开发者ID:GroupXTech,项目名称:Yatse2,代码行数:4,代码来源:AnyImporter.cs

示例7: TestValue

        private static void TestValue(object expected, JsonReader reader, string path)
        {
            if (JsonNull.LogicallyEquals(expected))
            {
                Assert.AreEqual(JsonTokenClass.Null, reader.TokenClass, path);
            }
            else
            {
                TypeCode expectedType = Type.GetTypeCode(expected.GetType());

                if (expectedType == TypeCode.Object)
                {
                    if (expected.GetType().IsArray)
                        TestArray((Array) expected, reader, path);
                    else
                        TestObject((JsonObject) expected, reader, path);
                }
                else
                {
                    switch (expectedType)
                    {
                        case TypeCode.String : Assert.AreEqual(expected, reader.ReadString(), path); break;
                        case TypeCode.Int32  : Assert.AreEqual(expected, (int) reader.ReadNumber(), path); break;
                        default : Assert.Fail("Don't know how to handle {0} values.", expected.GetType()); break;
                    }
                }
            }
        }
开发者ID:BackupTheBerlios,项目名称:jayrock-svn,代码行数:28,代码来源:TestComponentExporter.cs

示例8: ReadObject

        private static Object ReadObject(ref JsonReader jsonReader)
        {
            var jsonObject = new Object();
            var jsonMembersList = new List<Members>();
            List<Pair> jsonPairs = null;

            while (jsonReader.Read())
            {
                switch (jsonReader.TokenType)
                {
                    case JsonReader.JsonTokenType.Start:
                        break;
                    case JsonReader.JsonTokenType.ObjectStart:
                        jsonPairs = new List<Pair>();
                        break;
                    case JsonReader.JsonTokenType.ObjectEnd:
                        if (jsonPairs != null)
                        {
                            var jsonMembers = new Members {Pairs = jsonPairs};
                            jsonMembersList.Add(jsonMembers);
                            jsonObject.Members = jsonMembersList;
                            return jsonObject;
                        }
                        break;
                    case JsonReader.JsonTokenType.ArrayStart:
                        break;
                    case JsonReader.JsonTokenType.ArrayEnd:
                        break;
                    case JsonReader.JsonTokenType.Pair:
                        var pair = new Pair
                        {
                            Name = (string) jsonReader.ReadString(),
                            Value = GetValue(ref jsonReader)
                        };
                        if (jsonPairs != null) jsonPairs.Add(pair);
                        break;
                    case JsonReader.JsonTokenType.Value:
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
            throw new FormatException("Json object was started but never ended.");
        }
开发者ID:Anniepoh,项目名称:corefxlab,代码行数:44,代码来源:JsonReaderTests.cs

示例9: ReadJsonHelper

        private static void ReadJsonHelper(JsonReader jsonReader, ICollection<Members> jsonMembersMain)
        {
            Array jsonArray = null;
            List<Pair> jsonPairs = null;
            List<Value> jsonValues = null;

            while (jsonReader.Read())
            {
                switch (jsonReader.TokenType)
                {
                    case JsonReader.JsonTokenType.Start:
                        break;
                    case JsonReader.JsonTokenType.ObjectStart:
                        jsonPairs = new List<Pair>();
                        break;
                    case JsonReader.JsonTokenType.ObjectEnd:
                        if (jsonPairs != null)
                        {
                            var jsonMembers = new Members {Pairs = jsonPairs};
                            jsonMembersMain.Add(jsonMembers);
                        }
                        break;
                    case JsonReader.JsonTokenType.ArrayStart:
                        jsonArray = new Array();
                        jsonValues = new List<Value>();
                        break;
                    case JsonReader.JsonTokenType.ArrayEnd:
                        if (jsonArray != null)
                        {
                            var jsonElements = new Elements {Values = jsonValues};
                            jsonArray.Elements = new List<Elements> {jsonElements};
                        }
                        break;
                    case JsonReader.JsonTokenType.Pair:
                        var pair = new Pair
                        {
                            Name = (string) jsonReader.ReadString(),
                            Value = GetValue(ref jsonReader)
                        };
                        if (jsonPairs != null) jsonPairs.Add(pair);
                        break;
                    case JsonReader.JsonTokenType.Value:
                        if (jsonValues != null) jsonValues.Add(GetValue(ref jsonReader));
                        break;
                    default:
                        throw new ArgumentOutOfRangeException();
                }
            }
        }
开发者ID:Anniepoh,项目名称:corefxlab,代码行数:49,代码来源:JsonReaderTests.cs

示例10: DeserializeMeta

		private GraphMeta DeserializeMeta (ZipEntry entry) {
			if (entry == null) throw new Exception("No metadata found in serialized data.");

#if !ASTAR_NO_JSON
			string s = GetString(entry);

			var reader = new JsonReader(s, readerSettings);
			return (GraphMeta)reader.Deserialize(typeof(GraphMeta));
#else
			var meta = new GraphMeta();

			var reader = GetBinaryReader(entry);
			if (reader.ReadString() != "A*") throw new System.Exception("Invalid magic number in saved data");
			int major = reader.ReadInt32();
			int minor = reader.ReadInt32();
			int build = reader.ReadInt32();
			int revision = reader.ReadInt32();

			// Required because when saving a version with a field not set, it will save it as -1
			// and then the Version constructor will throw an exception (which we do not want)
			if (major < 0) meta.version = new Version(0, 0);
			else if (minor < 0) meta.version = new Version(major, 0);
			else if (build < 0) meta.version = new Version(major, minor);
			else if (revision < 0) meta.version = new Version(major, minor, build);
			else meta.version = new Version(major, minor, build, revision);

			meta.graphs = reader.ReadInt32();

			meta.guids = new string[reader.ReadInt32()];
			for (int i = 0; i < meta.guids.Length; i++) meta.guids[i] = reader.ReadString();

			meta.typeNames = new string[reader.ReadInt32()];
			for (int i = 0; i < meta.typeNames.Length; i++) meta.typeNames[i] = reader.ReadString();

			meta.nodeCounts = new int[reader.ReadInt32()];
			for (int i = 0; i < meta.nodeCounts.Length; i++) meta.nodeCounts[i] = reader.ReadInt32();

			return meta;
#endif
		}
开发者ID:Alx666,项目名称:ProjectPhoenix,代码行数:40,代码来源:JsonSerializer.cs


注:本文中的JsonReader.ReadString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。