• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# JsonToken类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中JsonToken的典型用法代码示例。如果您正苦于以下问题:C# JsonToken类的具体用法?C# JsonToken怎么用?C# JsonToken使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



JsonToken类属于命名空间,在下文中一共展示了JsonToken类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: AssertRead

        protected void AssertRead(JsonToken expectedToken)
        {
            Reader.Read();

            if (Reader.TokenType != expectedToken)
                throw new Exception("Expected " + expectedToken + " but got " + Reader.TokenType);
        }
开发者ID:brahmgupta,项目名称:GeoJsonSharp,代码行数:7,代码来源:BaseParser.cs


示例2: EnsureEnum

        protected void EnsureEnum(JsonToken token, object value)
        {
            if (Schema._enum != null && Schema._enum.Count > 0)
            {
                if (JsonTokenHelpers.IsPrimitiveOrStartToken(token))
                {
                    if (Context.TokenWriter == null)
                    {
                        Context.TokenWriter = new JTokenWriter();
                        Context.TokenWriter.WriteToken(token, value);
                    }
                }

                if (JsonTokenHelpers.IsPrimitiveOrEndToken(token))
                {
                    if (!Schema._enum.ContainsValue(Context.TokenWriter.CurrentToken, JToken.EqualityComparer))
                    {
                        StringWriter sw = new StringWriter(CultureInfo.InvariantCulture);
                        Context.TokenWriter.CurrentToken.WriteTo(new JsonTextWriter(sw));

                        RaiseError($"Value {sw.ToString()} is not defined in enum.", ErrorType.Enum, Schema, value, null);
                    }
                }
            }
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:25,代码来源:SchemaScope.cs


示例3: EvaluateToken

 public void EvaluateToken(JsonToken token, object value, int depth)
 {
     if (EvaluateTokenCore(token, value, depth))
     {
         Complete = true;
     }
 }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:7,代码来源:Scope.cs


示例4: JsonSerializer

		private JsonSerializer bareserializer = new JsonSerializer(); // full default settings, separate context

		private static void ReadExpectType(JsonReader reader, JsonToken expected)
		{
			if (!reader.Read())
				throw new InvalidOperationException();
			if (reader.TokenType != expected)
				throw new InvalidOperationException();
		}
开发者ID:CadeLaRen,项目名称:BizHawk,代码行数:9,代码来源:ExtraConverters.cs


示例5: EvaluateTokenCore

        protected override bool EvaluateTokenCore(JsonToken token, object value, int depth)
        {
            if (depth == InitialDepth && JsonTokenHelpers.IsPrimitiveOrEndToken(token))
            {
                int validCount = GetChildren().Count(IsValidPredicate);

                if (validCount != 1)
                {
                    List<int> validIndexes = new List<int>();
                    int index = 0;
                    foreach (SchemaScope schemaScope in GetChildren())
                    {
                        if (schemaScope.IsValid)
                            validIndexes.Add(index);

                        index++;
                    }

                    string message = "JSON is valid against more than one schema from 'oneOf'. ";
                    if (validIndexes.Count > 0)
                        message += "Valid schema indexes: {0}.".FormatWith(CultureInfo.InvariantCulture, StringHelpers.Join(", ", validIndexes));
                    else
                        message += "No valid schemas.";

                    RaiseError(message, ErrorType.OneOf, ParentSchemaScope.Schema, null, ConditionalContext.Errors);
                }

                return true;
            }

            return false;
        }
开发者ID:Nangal,项目名称:Newtonsoft.Json.Schema,代码行数:32,代码来源:OneOfScope.cs


示例6: Read

		public override bool Read()
		{
			LBTOK l = (LBTOK)r.ReadByte();
			switch (l)
			{
				case LBTOK.StartArray: t = JsonToken.StartArray; v = null; break;
				case LBTOK.EndArray: t = JsonToken.EndArray; v = null; break;
				case LBTOK.StartObject: t = JsonToken.StartObject; v = null; break;
				case LBTOK.EndObject: t = JsonToken.EndObject; v = null; break;
				case LBTOK.Null: t = JsonToken.Null; v = null; break;
				case LBTOK.False: t = JsonToken.Boolean; v = false; break;
				case LBTOK.True: t = JsonToken.Boolean; v = true; break;
				case LBTOK.Property: t = JsonToken.PropertyName; v = r.ReadString(); break;
				case LBTOK.Undefined: t = JsonToken.Undefined; v = null; break;
				case LBTOK.S8: t = JsonToken.Integer; v = r.ReadSByte(); break;
				case LBTOK.U8: t = JsonToken.Integer; v = r.ReadByte(); break;
				case LBTOK.S16: t = JsonToken.Integer; v = r.ReadInt16(); break;
				case LBTOK.U16: t = JsonToken.Integer; v = r.ReadUInt16(); break;
				case LBTOK.S32: t = JsonToken.Integer; v = r.ReadInt32(); break;
				case LBTOK.U32: t = JsonToken.Integer; v = r.ReadUInt32(); break;
				case LBTOK.S64: t = JsonToken.Integer; v = r.ReadInt64(); break;
				case LBTOK.U64: t = JsonToken.Integer; v = r.ReadUInt64(); break;
				case LBTOK.String: t = JsonToken.String; v = r.ReadString(); break;
				case LBTOK.F32: t = JsonToken.Float; v = r.ReadSingle(); break;
				case LBTOK.F64: t = JsonToken.Float; v = r.ReadDouble(); break;
				case LBTOK.ByteArray: t = JsonToken.Bytes; v = r.ReadBytes(r.ReadInt32()); break;

				default:
					throw new InvalidOperationException();
			}
			return true;
		}
开发者ID:henke37,项目名称:BizHawk,代码行数:32,代码来源:LBSON.cs


示例7: EvaluateTokenCore

        protected override bool EvaluateTokenCore(JsonToken token, object value, int depth)
        {
            if (depth == InitialDepth && JsonTokenHelpers.IsPrimitiveOrEndToken(token))
            {
                if (!GetChildren().All(IsValidPredicate))
                {
                    List<int> invalidIndexes = new List<int>();
                    int index = 0;
                    foreach (SchemaScope schemaScope in GetChildren())
                    {
                        if (!schemaScope.IsValid)
                        {
                            invalidIndexes.Add(index);
                        }

                        index++;
                    }

                    IFormattable message = $"JSON does not match all schemas from 'allOf'. Invalid schema indexes: {StringHelpers.Join(", ", invalidIndexes)}.";
                    RaiseError(message, ErrorType.AllOf, ParentSchemaScope.Schema, null, ConditionalContext.Errors);
                }

                return true;
            }

            return false;
        }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:27,代码来源:AllOfScope.cs


示例8: ValidateCurrentToken

        public void ValidateCurrentToken(JsonToken token, object value, int depth)
        {
            if (_scopes.Count == 0)
            {
                if (Schema == null)
                    throw new JSchemaException("No schema has been set for the validator.");

                LicenseHelpers.IncrementAndCheckValidationCount();
                SchemaScope.CreateTokenScope(token, Schema, _context, null, depth);
            }

            if (TokenWriter != null)
                TokenWriter.WriteToken(token, value);

            for (int i = _scopes.Count - 1; i >= 0; i--)
            {
                Scope scope = _scopes[i];

                if (!scope.Complete)
                    scope.EvaluateToken(token, value, depth);
                else
                    _scopes.RemoveAt(i);
            }

            if (TokenWriter != null && TokenWriter.Top == 0)
                TokenWriter = null;
        }
开发者ID:Nangal,项目名称:Newtonsoft.Json.Schema,代码行数:27,代码来源:Validator.cs


示例9: SkipJsonToken

        protected static object SkipJsonToken(JsonReader reader, JsonToken type)
        {
            if (!reader.Read() || reader.TokenType != type)
                throw new InvalidDataException(string.Format("Invalid JSON, expected \"{0}\", but got {1}, {2}", type, reader.TokenType, reader.Value));

            return reader.Value;
        }
开发者ID:admz,项目名称:duplicati,代码行数:7,代码来源:VolumeReaderBase.cs


示例10: InitializeScopes

 public void InitializeScopes(JsonToken token, List<JSchema> schemas)
 {
     foreach (JSchema schema in schemas)
     {
         SchemaScope.CreateTokenScope(token, schema, ConditionalContext, this, InitialDepth);
     }
 }
开发者ID:Pondidum,项目名称:Newtonsoft.Json.Schema,代码行数:7,代码来源:ConditionalScope.cs


示例11: PushBack

 internal void PushBack(JsonToken token)
 {
     if (bufferedToken != null)
     {
         throw new InvalidOperationException("Can't push back twice");
     }
     bufferedToken = token;
 }
开发者ID:stammen,项目名称:protobuf,代码行数:8,代码来源:JsonTokenizer.cs


示例12: WriteEnd

 protected override void WriteEnd(JsonToken token)
 {
   base.WriteEnd(token);
   this.RemoveParent();
   if (this.Top != 0)
     return;
   this._writer.WriteToken(this._root);
 }
开发者ID:tanis2000,项目名称:FEZ,代码行数:8,代码来源:BsonWriter.cs


示例13: ReadJsonProperty

        protected static object ReadJsonProperty(JsonReader reader, string propertyname, JsonToken type)
        {
            var p = SkipJsonToken(reader, JsonToken.PropertyName);
            if (p == null || p.ToString() != propertyname)
                throw new InvalidDataException(string.Format("Invalid JSON, expected property \"{0}\", but got {1}, {2}", propertyname, reader.TokenType, reader.Value));

            return SkipJsonToken(reader, type);
        }
开发者ID:admz,项目名称:duplicati,代码行数:8,代码来源:VolumeReaderBase.cs


示例14: Read

 static void Read(JsonReader jsonReader, JsonToken expected)
 {
     jsonReader.Read();
     if (jsonReader.TokenType != expected)
     {
         throw new Exception(string.Format("expected {0}", expected));
     }
 }
开发者ID:NuGet,项目名称:NuGet.Services.Metadata,代码行数:8,代码来源:DownloadRankings.cs


示例15: ReadState

			public ReadState(JsonToken type, object val = null)
			{
				TokenType = type;
				if(type == JsonToken.String && val != null)
					Value = val.ToString();
				else
					Value = val;
			}
开发者ID:remcoros,项目名称:ravendb,代码行数:8,代码来源:RavenJTokenReader.cs


示例16: CreateTokenScope

        public static SchemaScope CreateTokenScope(JsonToken token, JSchema schema, ContextBase context, Scope parent, int depth)
        {
            SchemaScope scope;

            switch (token)
            {
                case JsonToken.StartObject:
                    var objectScope = new ObjectScope(context, parent, depth, schema);
                    context.Scopes.Add(objectScope);

                    objectScope.InitializeScopes(token);

                    scope = objectScope;
                    break;
                case JsonToken.StartArray:
                case JsonToken.StartConstructor:
                    scope = new ArrayScope(context, parent, depth, schema);
                    context.Scopes.Add(scope);
                    break;
                default:
                    scope = new PrimativeScope(context, parent, depth, schema);
                    context.Scopes.Add(scope);
                    break;
            }

            if (schema._allOf != null && schema._allOf.Count > 0)
            {
                AllOfScope allOfScope = new AllOfScope(scope, context, depth);
                context.Scopes.Add(allOfScope);

                allOfScope.InitializeScopes(token, schema._allOf);
            }
            if (schema._anyOf != null && schema._anyOf.Count > 0)
            {
                AnyOfScope anyOfScope = new AnyOfScope(scope, context, depth);
                context.Scopes.Add(anyOfScope);

                anyOfScope.InitializeScopes(token, schema._anyOf);
            }
            if (schema._oneOf != null && schema._oneOf.Count > 0)
            {
                OneOfScope oneOfScope = new OneOfScope(scope, context, depth);
                context.Scopes.Add(oneOfScope);

                oneOfScope.InitializeScopes(token, schema._oneOf);
            }
            if (schema.Not != null)
            {
                NotScope notScope = new NotScope(scope, context, depth);
                context.Scopes.Add(notScope);

                notScope.InitializeScopes(token, Enumerable.Repeat(schema.Not, 1));
            }

            return scope;
        }
开发者ID:bmperdue,项目名称:Newtonsoft.Json.Schema,代码行数:56,代码来源:SchemaScope.cs


示例17: WriteEnd

    /// <summary>
    /// Writes the end.
    /// </summary>
    /// <param name="token">The token.</param>
    protected override void WriteEnd(JsonToken token)
    {
      base.WriteEnd(token);
      RemoveParent();

      if (Top == 0)
      {
        _writer.WriteToken(_root);
      }
    }
开发者ID:AugustoAngeletti,项目名称:blockspaces,代码行数:14,代码来源:BsonWriter.cs


示例18: IsPrimitiveType

 private static bool IsPrimitiveType(JsonToken type)
 {
     bool isPrimitive = type == JsonToken.Integer
         || type == JsonToken.Integer
         || type == JsonToken.Float
         || type == JsonToken.String
         || type == JsonToken.Boolean
         || type == JsonToken.Null;
     return isPrimitive;
 }
开发者ID:ankushraizada,项目名称:Dynamo,代码行数:10,代码来源:JsonDecoder.cs


示例19: IsEndToken

 internal static bool IsEndToken(JsonToken token)
 {
     switch (token)
     {
         case JsonToken.EndObject:
         case JsonToken.EndArray:
         case JsonToken.EndConstructor:
             return true;
         default:
             return false;
     }
 }
开发者ID:sat1582,项目名称:CODEFramework,代码行数:12,代码来源:JsonTokenUtils.cs


示例20: WriteEnd

	/// <summary>
	/// Writes the specified end token.
	/// </summary>
	protected override void WriteEnd(JsonToken token)
	{
		switch (token)
		{
			case JsonToken.EndArray:
				this.isArray = false;
				this.path.Pop();
				break;
			default:
				break;
		}
	}
开发者ID:netfx,项目名称:extensions,代码行数:15,代码来源:UsonWriter.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# JsonType类代码示例发布时间:2022-05-24
下一篇:
C# JsonTextWriter类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap