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


C# Json.JsonTextReader类代码示例

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


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

示例1: HandleLoadedProperty

	protected override void HandleLoadedProperty (JsonTextReader reader, string propertyName, object readValue) {
		base.HandleLoadedProperty (reader, propertyName, readValue);
		switch(propertyName) {
			case "AimRotation": aimRotation = LoadManager.LoadQuaternion(reader); break;
			default: break;
		}
	}
开发者ID:LeeWangyeol,项目名称:unity-rts-demo,代码行数:7,代码来源:Tank.cs

示例2: ReadRedirects

        public static List<Redirect> ReadRedirects(HttpContext context)
        {
            if (RedirectHandler.Redirects == null)
            {
                string path = WebConfigurationManager.AppSettings["redirects"] ?? "~/App_Data/redirects.json";
                path = context.Server.MapPath(path);

                List<Redirect> newRedirects = new List<Redirect>();

                using (TextReader file = File.OpenText(path))
                using (JsonTextReader reader = new JsonTextReader(file))
                {
                    string from = null;
                    while (reader.Read())
                    {
                        if (reader.TokenType == JsonToken.PropertyName)
                        {
                            from = ((string)reader.Value).ToLowerInvariant();
                        }
                        else if (reader.TokenType == JsonToken.String)
                        {
                            newRedirects.Add(new Redirect() { From = from, To = ((string)reader.Value).ToLowerInvariant() });
                        }
                    }
                }

                RedirectHandler.Redirects = newRedirects;
            }

            return RedirectHandler.Redirects;
        }
开发者ID:jchoover,项目名称:site,代码行数:31,代码来源:RedirectHandler.cs

示例3: ConstructorTest

        public void ConstructorTest()
        {
            string repositoryName = "Mvc3Application";
            string appName = "ConstructorTest";

            using (var repo = Git.CreateLocalRepository(repositoryName))
            {
                ApplicationManager.Run(appName, appManager =>
                {
                    using (HttpClient client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials))
                    {
                        HttpResponseMessage response = client.GetAsync("diagnostics/settings").Result.EnsureSuccessful();
                        using (var reader = new JsonTextReader(new StreamReader(response.Content.ReadAsStreamAsync().Result)))
                        {
                            JObject json = (JObject)JToken.ReadFrom(reader);
                            Assert.Equal(0, json.Count);
                        }
                    }

                    using (HttpClient client = HttpClientHelper.CreateClient(appManager.ServiceUrl, appManager.DeploymentManager.Credentials))
                    {
                        var ex = Assert.Throws<HttpRequestException>(() => client.GetAsync("diagnostics/settings/trace_level").Result.EnsureSuccessful());
                        Assert.Contains("404", ex.Message);
                    }
                });
            }
        }
开发者ID:lookworld,项目名称:kudu,代码行数:27,代码来源:DiagnosticsApiFacts.cs

示例4: LoadColor

 public static Color LoadColor(JsonTextReader reader)
 {
     if (reader == null) return new Color(0, 0, 0, 0);
     Color color = new Color(0, 0, 0, 0);
     string currVal = "";
     while (reader.Read())
     {
         if (reader.Value != null)
         {
             if (reader.TokenType == JsonToken.PropertyName) currVal = (string)reader.Value;
             else
             {
                 switch (currVal)
                 {
                     case "r": color.r = (float)(double)reader.Value; break;
                     case "g": color.g = (float)(double)reader.Value; break;
                     case "b": color.b = (float)(double)reader.Value; break;
                     case "a": color.a = (float)(double)reader.Value; break;
                     default: break;
                 }
             }
         }
         else if (reader.TokenType == JsonToken.EndObject) return color;
     }
     return color;
 }
开发者ID:amaximan,项目名称:educational,代码行数:26,代码来源:LoadManager.cs

示例5: Load

        public static void Load()
        {
            players.Clear();

            string filename = "SavedGames" + Path.DirectorySeparatorChar + "Players.json";
            if (File.Exists(filename))
            {
                //read contents of file
                string input;
                using (StreamReader sr = new StreamReader(filename))
                {
                    input = sr.ReadToEnd();
                }
                if (input != null)
                {
                    //parse contents of file
                    using (JsonTextReader reader = new JsonTextReader(new StringReader(input)))
                    {
                        while (reader.Read())
                        {
                            if (reader.Value != null)
                            {
                                if (reader.TokenType == JsonToken.PropertyName)
                                {
                                    if ((string)reader.Value == "Players") LoadPlayers(reader);
                                }
                            }
                        }
                    }
                }
            }
        }
开发者ID:amaximan,项目名称:educational,代码行数:32,代码来源:PlayerManager.cs

示例6: YahooFinance

    public void YahooFinance()
    {
      string input = @"{
""matches"" : [
{""t"":""C"", ""n"":""Citigroup Inc."", ""e"":""NYSE"", ""id"":""662713""}
,{""t"":""CHL"", ""n"":""China Mobile Ltd. (ADR)"", ""e"":""NYSE"", ""id"":""660998""}
,{""t"":""PTR"", ""n"":""PetroChina Company Limited (ADR)"", ""e"":""NYSE"", ""id"":""664536""}
,{""t"":""RIO"", ""n"":""Companhia Vale do Rio Doce (ADR)"", ""e"":""NYSE"", ""id"":""671472""}
,{""t"":""RIOPR"", ""n"":""Companhia Vale do Rio Doce (ADR)"", ""e"":""NYSE"", ""id"":""3512643""}
,{""t"":""CSCO"", ""n"":""Cisco Systems, Inc."", ""e"":""NASDAQ"", ""id"":""99624""}
,{""t"":""CVX"", ""n"":""Chevron Corporation"", ""e"":""NYSE"", ""id"":""667226""}
,{""t"":""TM"", ""n"":""Toyota Motor Corporation (ADR)"", ""e"":""NYSE"", ""id"":""655880""}
,{""t"":""JPM"", ""n"":""JPMorgan Chase \\x26 Co."", ""e"":""NYSE"", ""id"":""665639""}
,{""t"":""COP"", ""n"":""ConocoPhillips"", ""e"":""NYSE"", ""id"":""1691168""}
,{""t"":""LFC"", ""n"":""China Life Insurance Company Ltd. (ADR)"", ""e"":""NYSE"", ""id"":""688679""}
,{""t"":""NOK"", ""n"":""Nokia Corporation (ADR)"", ""e"":""NYSE"", ""id"":""657729""}
,{""t"":""KO"", ""n"":""The Coca-Cola Company"", ""e"":""NYSE"", ""id"":""6550""}
,{""t"":""VZ"", ""n"":""Verizon Communications Inc."", ""e"":""NYSE"", ""id"":""664887""}
,{""t"":""AMX"", ""n"":""America Movil S.A.B de C.V. (ADR)"", ""e"":""NYSE"", ""id"":""665834""}],
""all"" : false
}
";

      using (JsonReader jsonReader = new JsonTextReader(new StringReader(input)))
      {
        while (jsonReader.Read())
        {
          Console.WriteLine(jsonReader.Value);
        }
      }
    }
开发者ID:handcraftsman,项目名称:Newtonsoft.Json,代码行数:31,代码来源:JsonTextReaderTest.cs

示例7: ParseStepsAsync

        private async Task ParseStepsAsync(
            Stream stream,
            RecipeDescriptor descriptor,
            Func<RecipeDescriptor, RecipeStepDescriptor, Task> stepActionAsync)
        {
            var serializer = new JsonSerializer();

            StreamReader streamReader = new StreamReader(stream);
            JsonTextReader reader = new JsonTextReader(streamReader);

            // Go to Steps, then iterate.
            while (reader.Read())
            {
                if (reader.Path == "steps" && reader.TokenType == JsonToken.StartArray)
                {
                    int stepId = 0;
                    while (reader.Read() && reader.Depth > 1)
                    {
                        if (reader.Depth == 2)
                        {
                            var child = JToken.Load(reader);
                            await stepActionAsync(descriptor, new RecipeStepDescriptor
                            {
                                Id = (stepId++).ToString(CultureInfo.InvariantCulture),
                                RecipeName = descriptor.Name,
                                Name = child.Value<string>("name"),
                                Step = child
                            });
                        }
                    }
                }
            }
        }
开发者ID:jchenga,项目名称:Orchard2,代码行数:33,代码来源:JsonRecipeParser.cs

示例8: Load

        public void Load(ZipArchive iArchive)
        {
            JObject pJOtImages = null;
            ZipArchiveEntry pZAEImages = iArchive.GetEntry("images.json");
            if (pZAEImages != null)
            {
                using (Stream pStmImages = pZAEImages.Open())
                {
                    using (StreamReader pSRrReader = new StreamReader(pStmImages, Encoding.UTF8, false, 1024, true))
                    {
                        using (JsonTextReader pJTRReader = new JsonTextReader(pSRrReader))
                        {
                            pJOtImages = JObject.Load(pJTRReader);
                        }
                    }
                }
            }

            JArray pJAyImages = pJOtImages["images"].Value<JArray>(); ;
            foreach(JObject curImage in pJAyImages)
            {
                ProjectImage pPIeImage = ProjectImage.FromJSON(curImage);
                ZipArchiveEntry pZAEImage = iArchive.GetEntry(pPIeImage.ID);
                if (pZAEImage != null)
                {
                    using (Stream pStmImage = pZAEImage.Open())
                    {
                        pPIeImage.Image = Image.FromStream(pStmImage);
                        cDicImages.Add(pPIeImage.ID, pPIeImage);
                    }
                }
            }
        }
开发者ID:devoctomy,项目名称:knitup,代码行数:33,代码来源:ProjectImages.cs

示例9: makeRequestForm

        public RequestForm makeRequestForm(JObject json)
        {
            string currManagerName = (string)json["current"]["bazookaInfo"]["managerId"];
            string futureManagerName = (string)json["future"]["bazookaInfo"]["managerId"];
            int managerID = GetIDFromName(currManagerName);
            int f_managerID = GetIDFromName(futureManagerName);
            json["current"]["bazookaInfo"]["managerId"] = managerID;
            json["current"]["ultiproInfo"]["supervisor"] = managerID;
            json["future"]["bazookaInfo"]["managerId"] = f_managerID;
            json["future"]["ultiproInfo"]["supervisor"] = f_managerID;

            UserController uc = new UserController();
            string[] name = uc.GetUserName().Split('.');
            string creatorName = name[0] + " " + name[1];
            int creatorID = GetIDFromName(creatorName);

            RequestForm obj = null;
            using (var sr = new StringReader(json.ToString()))
            using (var jr = new JsonTextReader(sr))
            {
                var js = new JsonSerializer();
                obj = (RequestForm)js.Deserialize<RequestForm>(jr);
            }
            obj.EmployeeId = GetIDFromName((string)json["name"]);
            obj.CreatedByID = creatorID;
            obj.Current.BazookaInfo.SecurityItemRights = "";
            obj.ReviewInfo.FilesToBeRemovedFrom = "(" + obj.Current.BazookaInfo.Group + ")" + currManagerName.Replace(" ", ".")+" "+obj.ReviewInfo.FilesToBeRemovedFrom;
            obj.ReviewInfo.FilesToBeAddedTo = "(" + obj.Future.BazookaInfo.Group + ")" + futureManagerName.Replace(" ", ".")+" "+obj.ReviewInfo.FilesToBeAddedTo;

            return obj;
        }
开发者ID:jakemmarsh,项目名称:coyote-moves,代码行数:31,代码来源:RequestformController.cs

示例10: LoadGame

 public static void LoadGame(string filename)
 {
     char separator = Path.DirectorySeparatorChar;
     string path = "SavedGames" + separator + PlayerManager.GetPlayerName() + separator + filename + ".json";
     if(!File.Exists(path)) {
         Debug.Log("Unable to find " + path + ". Loading will crash, so aborting.");
         return;
     }
     string input;
     using(StreamReader sr = new StreamReader(path)) {
         input = sr.ReadToEnd();
     }
     if(input != null) {
         //parse contents of file
         using(JsonTextReader reader = new JsonTextReader(new StringReader(input))) {
             while(reader.Read()) {
                 if(reader.Value!=null) {
                     if(reader.TokenType == JsonToken.PropertyName) {
                         string property = (string)reader.Value;
                         switch(property) {
                             case "Sun": LoadLighting(reader); break;
                             case "Ground": LoadTerrain(reader); break;
                             case "Camera": LoadCamera(reader); break;
                             case "Resources": LoadResources(reader); break;
                             case "Players": LoadPlayers(reader); break;
                             default: break;
                         }
                     }
                 }
             }
         }
     }
 }
开发者ID:am200,项目名称:game2,代码行数:33,代码来源:LoadManager.cs

示例11: GetMedia

 public static ObservableCollection<MediaFile> GetMedia()
 {
     if (File.Exists(libraryCachePath))
     {
         using (var file = File.OpenRead(libraryCachePath))
         using (var sr = new StreamReader(file))
         using (var jtr = new JsonTextReader(sr))
         {
             return new ObservableCollection<MediaFile>(serializer.Deserialize<List<MediaFile>>(jtr));
         }
     }
     else
     {
         var library = RefreshLibrary();
         if (!Directory.Exists(Path.GetDirectoryName(libraryCachePath)))
         {
             Directory.CreateDirectory(Path.GetDirectoryName(libraryCachePath));
         }
         using (var file = File.Open(libraryCachePath, FileMode.Create))
         using (var sw = new StreamWriter(file))
         using (var jtr = new JsonTextWriter(sw))
         {
             serializer.Serialize(jtr, library);
         }
         return new ObservableCollection<MediaFile>(library);
     }
 }
开发者ID:ianobermiller,项目名称:SharpTunes,代码行数:27,代码来源:Library.cs

示例12: ReadBigInteger

        public void ReadBigInteger()
        {
            string json = @"{
    ParentId: 1,
    ChildId: 333333333333333333333333333333333333333,
}";

            JsonTextReader jsonTextReader = new JsonTextReader(new StringReader(json));

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(JsonToken.StartObject, jsonTextReader.TokenType);

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(JsonToken.PropertyName, jsonTextReader.TokenType);

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(JsonToken.Integer, jsonTextReader.TokenType);

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(JsonToken.PropertyName, jsonTextReader.TokenType);

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(JsonToken.Integer, jsonTextReader.TokenType);
            Assert.AreEqual(typeof(BigInteger), jsonTextReader.ValueType);
            Assert.AreEqual(BigInteger.Parse("333333333333333333333333333333333333333"), jsonTextReader.Value);

            Assert.IsTrue(jsonTextReader.Read());
            Assert.AreEqual(JsonToken.EndObject, jsonTextReader.TokenType);

            Assert.IsFalse(jsonTextReader.Read());

            JObject o = JObject.Parse(json);
            var i = (BigInteger)((JValue)o["ChildId"]).Value;
            Assert.AreEqual(BigInteger.Parse("333333333333333333333333333333333333333"), i);
        }
开发者ID:NitroXenon,项目名称:LoLSpectX,代码行数:35,代码来源:JsonTextReaderTest.cs

示例13: ReadFromStreamAsync

        //public JsonFormatter()
        //{
        //  SupportedMediaTypes.Add(new MediaTypeHeaderValue("text/json"));
        //  SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
        //}
        public override Task<object> ReadFromStreamAsync(Type type, Stream readStream, HttpContent content, IFormatterLogger formatterLogger)
        {
            var task = new TaskCompletionSource<object>();

              using (var ms = new MemoryStream())
              {
            readStream.CopyTo(ms);
            //ms.Seek(0, SeekOrigin.Begin);

            //var result = JsonSchemaValidator.Instance().Validate(ms, type);

            //if (!string.IsNullOrWhiteSpace(result))
            //  task.SetResult(result);
            //else
            {
              ms.Seek(0, SeekOrigin.Begin);
              using (var reader = new JsonTextReader(new StreamReader(ms)))
              {
            var serializer = new JsonSerializer();
            task.SetResult(serializer.Deserialize(reader, type));
              }
            }
              }
              return task.Task;
        }
开发者ID:shanmukhig,项目名称:tms,代码行数:30,代码来源:JsonFormatter.cs

示例14: Parse

        public void Parse()
        {
            if (_IsParsed) return;

            var json = Encoding.UTF8.GetString(this.data);
            using (var strReader = new System.IO.StringReader(json)) {
                using (var r = new JsonTextReader(strReader)) {
                    while (r.Read()) {
                        if (r.TokenType == JsonToken.PropertyName) {
                            switch (r.Value.ToString()) {
                                case "region":
                                    ParseRegions(r);
                                    break;
                                case "nonpop":
                                    _NonPops = r.ReadInt32Array();
                                    break;
                                case "item":
                                    _Items = r.ReadInt32Array();
                                    break;
                                case "instance_contents":
                                    _InstanceContents = r.ReadInt32Array();
                                    break;
                                default:
                                    Console.Error.WriteLine("Unknown 'BNpcName' data key: {0}", r.Value);
                                    throw new NotSupportedException();
                            }
                        }
                    }
                }
            }

            _IsParsed = true;
        }
开发者ID:KevinAllenWiegand,项目名称:SaintCoinach,代码行数:33,代码来源:BNpcName.Parse.cs

示例15: DeserializeXmlNode

    private XmlNode DeserializeXmlNode(string json, string deserializeRootElementName)
    {
      JsonTextReader reader;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XmlNodeConverter converter = new XmlNodeConverter();
      if (deserializeRootElementName != null)
        converter.DeserializeRootElementName = deserializeRootElementName;

      XmlNode node = (XmlNode)converter.ReadJson(reader, typeof (XmlDocument), null, new JsonSerializer());

#if !NET20
     string xmlText = node.OuterXml;

      reader = new JsonTextReader(new StringReader(json));
      reader.Read();
      XDocument d = (XDocument) converter.ReadJson(reader, typeof (XDocument), null, new JsonSerializer());

      string linqXmlText = d.ToString(SaveOptions.DisableFormatting);
      if (d.Declaration != null)
        linqXmlText = d.Declaration + linqXmlText;

      Assert.AreEqual(xmlText, linqXmlText);
#endif

      return node;
    }
开发者ID:pmorton,项目名称:Json.Net,代码行数:28,代码来源:XmlNodeConverterTest.cs


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