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


C# JsonTextWriter.WriteRaw方法代码示例

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


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

示例1: WriteToStream

 private void WriteToStream(Type type, object value, Stream writeStream, HttpContent content)
 {
     JsonSerializer serializer = JsonSerializer.Create(this.SerializerSettings);
     using (StreamWriter streamWriter = new StreamWriter(writeStream, this.SupportedEncodings.First()))
     using (JsonTextWriter jsonTextWriter = new JsonTextWriter(streamWriter) { CloseOutput = false })
     {
         jsonTextWriter.WriteRaw(this.Callback + "(");
         serializer.Serialize(jsonTextWriter, value);
         jsonTextWriter.WriteRaw(")");
     }
 }
开发者ID:chenboyi081,项目名称:asp-net-web-api-2-samples,代码行数:11,代码来源:JsonpMediaTypeFormatter.cs

示例2: Calibration_FrameArrived

        private void Calibration_FrameArrived(object sender, BodyFrameArrivedEventArgs e)
        {
            kc.Controller_FrameArrived(sender, e);

            if (kc.Arm != ArmPointing.Nothing)
            {
                float pointedX = kc.GetPointedX();
                float pointedY = kc.GetPointedY();

                DataLog.Log(DataLog.DebugLevel.Message, "Calibrated with X=" + pointedX.ToString() +
                    " Y=" + pointedY.ToString());

                if (!File.Exists(OPT_FILE))
                    File.Create(OPT_FILE).Close();

                List<float> l = new List<float>();

                l.Add(pointedX);
                l.Add(pointedY);

                StreamWriter cal_file = File.CreateText(OPT_FILE);
                JsonTextWriter cal_writer = new JsonTextWriter(cal_file);
                string data = JsonConvert.SerializeObject(l);
                cal_writer.WriteRaw(data);
                cal_file.Close();

                this.Close();
            }
        }
开发者ID:NoMore201,项目名称:InteractiveMediaWindow,代码行数:29,代码来源:CalibrationWindow.xaml.cs

示例3: SerializeToStreamAsync

        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var json = JsonConvert.SerializeObject(_value);

            using (var jw = new JsonTextWriter(new StreamWriter(stream)))
            {
                jw.WriteRaw(json);
                jw.Flush();
            }
        }
开发者ID:sk8tz,项目名称:Orc.LicenseManager,代码行数:10,代码来源:JsonContent.cs

示例4: SerializeToStreamAsync

 protected override Task SerializeToStreamAsync(Stream stream,
     TransportContext context)
 {
     var jw = new JsonTextWriter(new StreamWriter(stream))
     {
         Formatting = Formatting.Indented
     };
     jw.WriteRaw(JsonConvert.SerializeObject(_value));             
     jw.Flush();
     return Task.FromResult<object>(null);
 }
开发者ID:devmicrominds,项目名称:HIS-Project,代码行数:11,代码来源:JsonContent.cs

示例5: SerializeToStreamAsync

        protected override async Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var json = JsonConvert.SerializeObject(_value, Newtonsoft.Json.Formatting.None,
                new JsonSerializerSettings { ContractResolver = new CamelCasePropertyNamesContractResolver() });

            using (var jw = new JsonTextWriter(new StreamWriter(stream)))
            {
                jw.WriteRaw(json);
                jw.Flush();
            }
        }
开发者ID:chappoo,项目名称:GitReleaseNotes,代码行数:11,代码来源:JsonContent.cs

示例6: WriteJson

		public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
		{
			var p = value as GeoPrecision;
			if (p == null)
			{
				writer.WriteNull();
				return;
			}
			using (var sw = new StringWriter())
			using (var localWriter = new JsonTextWriter(sw))
			{
				serializer.Serialize(localWriter, p.Precision);
				localWriter.WriteRaw(p.Unit.GetStringValue());
				var s = sw.ToString();
				writer.WriteValue(s);
			}
		}
开发者ID:strongant,项目名称:elasticsearch-net,代码行数:17,代码来源:GeoPrecisionConverter.cs

示例7: SerializeToStreamAsync

        /// <summary>
        /// Metoda scrie un rezultatul serializarii in json a obiectului _responseValue
        /// </summary>
        protected override Task SerializeToStreamAsync(Stream stream, TransportContext context)
        {
            var jw = new JsonTextWriter(new StreamWriter(stream))
            {
                Formatting = Formatting.Indented
            };

            var jsonSettings = new JsonSerializerSettings()
            {
                ReferenceLoopHandling = ReferenceLoopHandling.Ignore,
                ContractResolver = _contractResolver
            };
            var jsonResult = JsonConvert.SerializeObject(_responseValue, jsonSettings);
            jw.WriteRaw(jsonResult);
            jw.Flush();
            return Task.FromResult<object>(null);
        }
开发者ID:gommjabbar,项目名称:sync,代码行数:20,代码来源:JsonContent.cs

示例8: ExecuteResult

        public override void ExecuteResult(ControllerContext context)
        {
            JsonTextWriter jwriter = new JsonTextWriter(context.HttpContext.Response.Output);

                context.HttpContext.Response.ContentType = "application/rss+json";
            if (!ObjectCacheManager<string>.Instance.Contains("DefaultFeed"))
            {
                StringWriter sw = new StringWriter();
                XmlDocument doc = new XmlDocument();
                Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(Feed);
                using (XmlWriter writer = XmlWriter.Create(sw))
                {
                    rssFormatter.WriteTo(writer);
                }
                doc.LoadXml(sw.ToString());

                ObjectCacheManager<string>.Instance.Add("DefaultFeed", JsonConvert.SerializeXmlNode(doc));
            }

            jwriter.WriteRaw(ObjectCacheManager<string>.Instance["DefaultFeed"]);
        }
开发者ID:jmdjr,项目名称:eqn-clan-website,代码行数:21,代码来源:RssActionResult.cs

示例9: TestResponse

        public static void TestResponse(string url, string fileName, string body = null, string method = Methods.Get, Codes expectedCode = Codes.Succeeded, string acceptHeader = null) {
            if (body != null && (method == Methods.Get || method == Methods.Delete)) {
                //Add the arguments as a url-encoded query string
                string args = HttpUtility.UrlEncode(body);
                url += "?" + args;
            }
            var httpRequest = (HttpWebRequest) WebRequest.Create(url);

            httpRequest.KeepAlive = false;
            httpRequest.Method = method;

            httpRequest.ContentType = @"application/json";
            if (acceptHeader != null) {
                httpRequest.Accept = acceptHeader;
            }
            if (body != null && method != Methods.Get) {
                httpRequest.ContentLength = body.Length;
                using (var sw = new StreamWriter(httpRequest.GetRequestStream())) {
                    using (var jr = new JsonTextWriter(sw)) {
                        jr.WriteRaw(body);
                    }
                }
            }
            else {
                httpRequest.ContentLength = 0;
            }

            if (expectedCode == Codes.Succeeded || expectedCode == Codes.SucceededNewRepresentation) {
                ErrorNotExpected(httpRequest, fileName);
            }
            else if (expectedCode == Codes.SucceededValidation) {
                ErrorNotExpectedNoContent(httpRequest);
            }
            else {
                ErrorExpected(httpRequest, (int) expectedCode);
            }
        }
开发者ID:priaonehaha,项目名称:NakedObjectsFramework,代码行数:37,代码来源:Helpers.cs

示例10: InitializeConfiguration

        protected static void InitializeConfiguration()
        {
            new Configuration();
            Console.WriteLine("Configuration loaded!");
            Thread.Sleep(1000);
            var usingmysql = Configuration.IsMySQLEnabled ? "YES" : "NO";
            Console.WriteLine("Using MySQL: " + usingmysql);
            if (Configuration.IsMySQLEnabled)
            {
                Console.WriteLine("Connecting to MySQL");
                new WebService();
                while (!WebService.ConnectionEntablished)
                    Thread.Sleep(100);
                Console.WriteLine("Connected!");
            }
            else if (!File.Exists("Settings.ini"))
            {
                Console.WriteLine("Configuration file not found. Enter required information." + Environment.NewLine);

                Console.Write("League of Legends game path: ");
                var GamePath = Console.ReadLine();

                Console.Write(Environment.NewLine + "Select region [EUW, EUNE, NA, TR, ...]: ");
                var Region = Console.ReadLine();

                Console.Write(Environment.NewLine + "Max bots value: ");
                var MaxBots = Console.ReadLine();

                Console.Write(Environment.NewLine + "Queue type: [ARAM, MEDIUM_BOT, EASY_BOT, NORMAL5X5]: ");
                var Queue = Console.ReadLine();


                string SelectedDifficulty = string.Empty;
                int SelectedQueue = int.MaxValue;

                switch (Queue)
                {
                    case "MEDIUM_BOT":
                        SelectedDifficulty = "MEDIUM";
                        SelectedQueue = 33;
                        break;
                    case "EASY_BOT":
                        SelectedQueue = 32;
                        SelectedDifficulty = "EASY";
                        break;
                    case "ARAM":
                        SelectedQueue = 65;
                        break;
                    case "NORMAL5X5":
                        SelectedQueue = 2;
                        break;
                }

                if (MaxBots == null || GamePath == null || SelectedQueue == int.MaxValue || Region == null)
                {
                    Console.WriteLine("Some of settings was left not set. Please run ChallengerBot again and set all settings as it should be.");    
                    return;
                }

                var mbots = String.Join("", MaxBots.Where(char.IsDigit));
                Settings SFile = new Settings
                {
                    GamePath = GamePath,
                    MaxBots = Convert.ToInt32(mbots),
                    Difficulty = SelectedDifficulty,
                    QueueType = SelectedQueue,
                    Region = Region.ToUpper()
                };


                WebService.Setting = SFile;
                using (StreamWriter file = File.CreateText("Settings.ini"))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    writer.WriteRaw(JsonConvert.SerializeObject(SFile, Formatting.Indented));
                }
                
                Thread.Sleep(1000);
                Console.WriteLine("Settings.ini file saved.");
            }
            else if (File.Exists("Settings.ini")) Configuration.LoadSettings();
     
            if (!File.Exists("accounts.txt") && !Configuration.IsMySQLEnabled)
            {
                Console.WriteLine("Missing accounts.txt file.");
                Console.WriteLine("One account per line. " + Environment.NewLine +
                                  " Format: accountname|accountpassword|maxlevel[1-31]|xpboostbuy[0 - NO and 1 YES]");
                while (true) Thread.Sleep(100);
            }
            else
            {
                int LoadedPlayers = 0;
                StreamReader file = new StreamReader("accounts.txt");
                string line;

                while ((line = file.ReadLine()) != null)
                {
                    string[] account = line.Split('|');

                    bool boost = account[3] != "0";
//.........这里部分代码省略.........
开发者ID:phanminh22,项目名称:ChallengerBot_WebControl,代码行数:101,代码来源:Client.cs

示例11: WriteEnvironmentSettings

        public static void WriteEnvironmentSettings(IEnumerable<LoadedEnvironments> environments)
        {
            string environmnentJsonFile = Path.Combine(Directory.GetCurrentDirectory(), ENVIRONMENT_FILE_NAME);

            try
            {
                using (StreamWriter file = File.CreateText(environmnentJsonFile))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    foreach (var environment in environments)
                    {
                        var jsonEnvironment = JsonConvert.SerializeObject(environment);
                        writer.WriteRaw(jsonEnvironment);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{Constants.EnvironmentMessages.ErrorWritingFile}{ex}",
                    Constants.EnvironmentMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
开发者ID:gr0ss,项目名称:RegistryMonitor,代码行数:23,代码来源:EnvironmentUtils.cs

示例12: ExecuteResult

            public override void ExecuteResult(ControllerContext context)
            {
                if (context == null)
                {
                    throw new ArgumentNullException("context");
                }

                var response = context.HttpContext.Response;

                response.ContentType = !string.IsNullOrEmpty(ContentType) ? ContentType : "application/json";

                if (Data != null)
                {
                    if (!AlreadyJson)
                    {
                        var writer = new JsonTextWriter(response.Output);
                        var settings = new JsonSerializerSettings();
                        settings.ContractResolver = new CamelCasePropertyNamesContractResolver();
                        settings.NullValueHandling = NullValueHandling.Ignore;
                        var serializer = JsonSerializer.Create(settings);
                        serializer.Serialize(writer, Data);
                        writer.Flush();
                    }
                    else
                    {
                        var writer = new JsonTextWriter(response.Output);
                        writer.WriteRaw(Data.ToString());
                        writer.Flush();
                    }
                }
            }
开发者ID:Rumel,项目名称:black-mesa,代码行数:31,代码来源:BaseController.cs

示例13: WriteToolsSettings

        public static void WriteToolsSettings(IEnumerable<LoadedTools> tools)
        {
            string toolJsonFile = Path.Combine(Directory.GetCurrentDirectory(), TOOLS_FILE_NAME);

            try
            {
                using (StreamWriter file = File.CreateText(toolJsonFile))
                using (JsonTextWriter writer = new JsonTextWriter(file))
                {
                    foreach (var tool in tools)
                    {
                        var jsonTool = JsonConvert.SerializeObject(tool);
                        writer.WriteRaw(jsonTool);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show($"{Constants.ToolMessages.ErrorWritingFile}{ex}",
                    Constants.ToolMessages.ErrorWritingFileCaption, MessageBoxButtons.OK, MessageBoxIcon.Error);
                throw;
            }
        }
开发者ID:gr0ss,项目名称:RegistryMonitor,代码行数:23,代码来源:ToolsUtils.cs

示例14: ParmsObjectAction

        public void ParmsObjectAction() {
            var url1 = "http://localhost:57840/objects/WithActionObject/1/actions/AnActionReturnsObjectWithParameters/invoke";
            var url2 = "http://localhost:57840/objects/WithActionObject/1/actions/AnActionReturnsCollectionWithParameters/invoke";

            var count = 1000;
            var urls = new[] { url1, url2 };

            for (int i = 0; i < count; i++) {

                //Console.WriteLine("Starting iteration#" + i);

                try {
                    var url = urls[i % urls.Length];

                    var httpRequest = (HttpWebRequest)WebRequest.Create(url);

                    httpRequest.KeepAlive = false;
                    httpRequest.Method = "POST";
                    

                    httpRequest.ContentType = @"application/json";

                    var parm1 = new JObject(new JProperty("value", 101));
                    var parm2 = new JObject(new JProperty("value", MostSimple1AsRef()));
                    var parms = new JObject(new JProperty("parm1", parm1), new JProperty("parm2", parm2)); 

                    var body = parms.ToString();

                    httpRequest.ContentLength = body.Length;
                    using (var sw = new StreamWriter(httpRequest.GetRequestStream())) {
                        using (var jr = new JsonTextWriter(sw)) {
                            jr.WriteRaw(body);
                        }
                    }

                    using (var response = (HttpWebResponse)httpRequest.GetResponse()) {
                        // Code here 

                        var rc = response.StatusCode;
                    }
                    //Console.WriteLine("Complete iteration#" + i);


                    Thread.Sleep(100);

                }
                catch (Exception e) {
                    //Console.WriteLine("Failed iteration#" + i  + " " + e.Message);
                }
            }
        }
开发者ID:NakedObjectsGroup,项目名称:NakedObjectsFramework,代码行数:51,代码来源:ObjectTest.cs

示例15: TrStmtList

        void TrStmtList(List<Statement/*!*/>/*!*/ stmts)
        {
            Contract.Requires(cce.NonNullElements(stmts));
              List<LocalVariable> AllDecls = new List<LocalVariable>();

              using (WriteArray()) {
            j.WriteValue(KremlinAst.ESequence);
            using (WriteArray()) {
              WriteEUnit(); // in case the statement list is empty
              foreach (Statement ss in stmts) {
            // JsonTextWriter is forward-only, but after calling TrStmt() we may need
            // to go back and inject new ELet statements to introduce temp variables.
            // So call TrStmt() once to generate code to a throw-away MemoryStream,
            // but remember what temps need to be introduced.  Then introduce them
            // and call TrStmt() once more, to generate the actual Json.
            JsonTextWriter oldj = j;
            VariableTracker oldtracker = VarTracker.Clone();

            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);
            JsonTextWriter newj = new JsonTextWriter(sw);
            newj.Formatting = oldj.Formatting;
            newj.Indentation = oldj.Indentation;
            j = newj;

            var oldVarDeclsList = varDeclsList;
            varDeclsList = new List<LocalVariable>();

            TrStmt(ss);

            j = oldj;
            VarTracker = oldtracker;
            var decls = varDeclsList; // Grab the set of just-declared variables generated by the first TrStmt() pass
            varDeclsList = null;      // Switch modes for next TrStmt() pass
            AllDecls.AddRange(decls); // Accumulate the set of all variables this stmt list has generated
            foreach (var l in decls) {
              // ELet v in { Stmt
              j.WriteStartArray();
              j.WriteValue(KremlinAst.ELet);
              j.WriteStartArray();
              WriteBinder(l, l.Name, true); // lident
              WriteDefaultValue(l.Type);    // = default
              VarTracker.Push(l);
              // "in" is the contents that follow
              j.WriteStartArray();
              j.WriteValue(KremlinAst.ESequence);
              j.WriteStartArray();
              WriteEUnit();
            }

            newj.Close();
            string RawJson = sb.ToString();
            if (RawJson != "") {
              j.WriteRaw(",");
              j.WriteWhitespace("\n");
              j.WriteRaw(RawJson); // Now paste the JSON
            }

            if (ss.Labels != null) {
              // bugbug: these appear to be used to support "Break" statements.
              j.WriteComment("Labels are unsupported: " + ss.Labels.Data.AssignUniqueId("after_", idGenerator));
            }

            varDeclsList = oldVarDeclsList;
              }

              // Now that all statements in the list have been generated, close out the nested ELets generated above
              AllDecls.Reverse();
              foreach (var l in AllDecls) {
            VarTracker.Pop(l);
            j.WriteEndArray(); // Closing out the expr list in the ESequence
            j.WriteEndArray(); // Closing out the array aboce ESequence
            j.WriteEndArray(); // Closing out the list of binder * expr * expr
            j.WriteEndArray(); // Closing out the array above ELet
              }
            }
              }
        }
开发者ID:Chris-Hawblitzel,项目名称:dafny,代码行数:78,代码来源:Kremlin.cs


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