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


C# JsonTextWriter.WriteToken方法代码示例

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


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

示例1: ReadJsonAsStringArray

        protected virtual object ReadJsonAsStringArray(JsonReader reader)
        {
            if (reader.TokenType != JsonToken.StartArray)
            {
                reader.Skip();
                return null;
            }

            var rowValues = new List<string>();
            var valueStartDepth = reader.Depth;
            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            {
                using (var jw = new JsonTextWriter(sw))
                {
                    while (reader.Read() && !(reader.TokenType == JsonToken.EndArray && reader.Depth == valueStartDepth))
                    {
                        jw.WriteToken(reader, true);
                        rowValues.Add(sb.ToString());
                        sb.Clear();
                    }
                }
            }

            return rowValues.ToArray();
        }
开发者ID:joaoportela,项目名称:mycouch,代码行数:27,代码来源:MultiTypeDeserializationJsonConverter.cs

示例2: Create

        /// <summary>
        /// Creates an instance of <see cref="JRaw"/> with the content of the reader's current token.
        /// </summary>
        /// <param name="reader">The reader.</param>
        /// <returns>An instance of <see cref="JRaw"/> with the content of the reader's current token.</returns>
        public static JRaw Create(JsonReader reader)
        {
            using (StringWriter sw = new StringWriter(CultureInfo.InvariantCulture))
            using (JsonTextWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.WriteToken(reader);

                return new JRaw(sw.ToString());
            }
        }
开发者ID:HaKDMoDz,项目名称:eStd,代码行数:15,代码来源:JRaw.cs

示例3: Create

 public static JRaw Create(JsonReader reader)
 {
   using (StringWriter stringWriter = new StringWriter((IFormatProvider) CultureInfo.InvariantCulture))
   {
     using (JsonTextWriter jsonTextWriter = new JsonTextWriter((TextWriter) stringWriter))
     {
       jsonTextWriter.WriteToken(reader);
       return new JRaw((object) stringWriter.ToString());
     }
   }
 }
开发者ID:Zeludon,项目名称:FEZ,代码行数:11,代码来源:JRaw.cs

示例4: formatButton_Click

        private void formatButton_Click(object sender, RoutedEventArgs e)
        {
            using (var stringReader = new StringReader(textBox.Text))
            using (var stringWriter = new StringWriter())
            {
                var jsonReader = new JsonTextReader(stringReader);
                var jsonWriter = new JsonTextWriter(stringWriter) { Formatting = Formatting.Indented };
                jsonWriter.WriteToken(jsonReader);
                textBox.Text = stringWriter.ToString();
            }

        }
开发者ID:robert-impey,项目名称:CodingExperiments,代码行数:12,代码来源:MainWindow.xaml.cs

示例5: ReadJsonAsString

        protected virtual object ReadJsonAsString(JsonReader reader)
        {
            var sb = new StringBuilder();

            using (var wo = new StringWriter(sb))
            {
                using (var w = new JsonTextWriter(wo))
                {
                    w.WriteToken(reader, true);
                }
            }

            return sb.ToString();
        }
开发者ID:joaoportela,项目名称:mycouch,代码行数:14,代码来源:MultiTypeDeserializationJsonConverter.cs

示例6: GetInnerJson

        public static string GetInnerJson(this JsonReader jsonReader)
        {
            if (jsonReader == null)
                throw new ArgumentNullException("jsonReader");

            if (jsonReader.TokenType == JsonToken.PropertyName)
                jsonReader.Read();

            var sb = new StringBuilder();

            using (var sw = new StringWriter(sb))
            using (var jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.WriteToken(jsonReader);
            }

            return sb.ToString();
        }
开发者ID:haoasqui,项目名称:ONLYOFFICE-Server,代码行数:18,代码来源:Extensions.cs

示例7: Import

        static void Import(AzureDataCatalog td, string exportedCatalogFilePath)
        {
            int totalAssetsImportSucceeded = 0;
            int totalAssetsImportFailed = 0;

            System.IO.StreamReader sr = new StreamReader(exportedCatalogFilePath);
            JsonTextReader reader = new JsonTextReader(sr);

            StringWriter sw = new StringWriter(new StringBuilder());

            JsonTextWriter jtw = new JsonTextWriter(sw);

            reader.Read();
            if (reader.TokenType != JsonToken.StartObject)
            {
                throw new Exception("Invalid Json. Expected StartObject");
            }

            reader.Read();
            if ((reader.TokenType != JsonToken.PropertyName) || (!reader.Value.ToString().Equals("catalog")))
            {
                throw new Exception("Invalid Json. Expected catalog array");
            }

            reader.Read();
            if (reader.TokenType != JsonToken.StartArray)
            {
                throw new Exception("Invalid Json. Expected StartArray");
            }

            while (reader.Read())
            {
                if (reader.TokenType == JsonToken.EndArray)
                    break;

                jtw.WriteToken(reader);

                JObject asset = JObject.Parse(sw.ToString());

                string id = asset["id"].ToString();
                asset.Remove("id");
                string[] idInfo = id.Split(new char[] { '/' });
                string newid;

                string UpdateResponse = td.Update(asset.ToString(), idInfo[idInfo.Length - 2], out newid);

                if ((UpdateResponse != null) && (!string.IsNullOrEmpty(newid)))
                {
                    totalAssetsImportSucceeded++;

                    if (totalAssetsImportSucceeded % 50 == 0)
                    {
                        System.Console.WriteLine(totalAssetsImportSucceeded + "Assets Imported Succesfully");
                    }
                }
                else
                {
                    totalAssetsImportFailed++;
                }

                //reset local variables for next iteration
                sw = new StringWriter(new StringBuilder());
                jtw = new JsonTextWriter(sw);

            }

            Console.WriteLine("Total Imported Success: " + totalAssetsImportSucceeded);
            Console.WriteLine("Total Imported Failed: " + totalAssetsImportFailed);
        }
开发者ID:Azure-Samples,项目名称:data-catalog-dotnet-import-export,代码行数:69,代码来源:Program.cs

示例8: WriteTokenDirect_BadValue

        public void WriteTokenDirect_BadValue()
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.WriteToken(JsonToken.StartArray);

                ExceptionAssert.Throws<FormatException>(() => { jsonWriter.WriteToken(JsonToken.Integer, "three"); }, "Input string was not in a correct format.");

                ExceptionAssert.Throws<ArgumentNullException>(() => { jsonWriter.WriteToken(JsonToken.Integer); }, @"Value cannot be null.
Parameter name: value");
            }
        }
开发者ID:Dylan-Jang,项目名称:Newtonsoft.Json,代码行数:15,代码来源:JsonTextWriterTest.cs

示例9: WriteTokenDirect

        public void WriteTokenDirect()
        {
            StringBuilder sb = new StringBuilder();
            StringWriter sw = new StringWriter(sb);

            using (JsonWriter jsonWriter = new JsonTextWriter(sw))
            {
                jsonWriter.WriteToken(JsonToken.StartArray);
                jsonWriter.WriteToken(JsonToken.Integer, 1);
                jsonWriter.WriteToken(JsonToken.StartObject);
                jsonWriter.WriteToken(JsonToken.PropertyName, "string");
                jsonWriter.WriteToken(JsonToken.Integer, int.MaxValue);
                jsonWriter.WriteToken(JsonToken.EndObject);
                jsonWriter.WriteToken(JsonToken.EndArray);
            }

            Assert.AreEqual(@"[1,{""string"":2147483647}]", sb.ToString());
        }
开发者ID:Dylan-Jang,项目名称:Newtonsoft.Json,代码行数:18,代码来源:JsonTextWriterTest.cs

示例10: JsonPrettify

 private static String JsonPrettify(string json)
 {
     using (var stringReader = new StringReader (json))
     using (var stringWriter = new StringWriter ())
     using (var jsonReader = new JsonTextReader (stringReader))
     using (var jsonWriter = new JsonTextWriter (stringWriter) { Formatting = Formatting.Indented }) {
         jsonWriter.WriteToken (jsonReader);
         return stringWriter.ToString ();
     }
 }
开发者ID:exzeo,项目名称:webhooks-consumer-csharp-sample,代码行数:10,代码来源:SampleJsonProcessor.cs

示例11: DumpCollection

        private async Task DumpCollection(Uri collection, IReliableServiceQuery proxy, JsonTextWriter jsonWriter)
        {
            Log($"Dumping collection {collection}");

            var collectionData = await proxy.GetCollectionData(collection);

            jsonWriter.WriteStartArray();

            foreach (var item in collectionData)
            {
                using (var reader = new JsonTextReader(new StringReader(item)))
                {
                    jsonWriter.WriteToken(reader);
                }
            }

            jsonWriter.WriteEndArray();
        }
开发者ID:aelij,项目名称:samples-servicefabric-reliablecollectionquery,代码行数:18,代码来源:Program.cs

示例12: TokenTypeOutOfRange

        public void TokenTypeOutOfRange()
        {
            using (JsonWriter jsonWriter = new JsonTextWriter(new StringWriter()))
            {
                ArgumentOutOfRangeException ex = ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => jsonWriter.WriteToken((JsonToken)int.MinValue));
                Assert.AreEqual("token", ex.ParamName);

                ex = ExceptionAssert.Throws<ArgumentOutOfRangeException>(() => jsonWriter.WriteToken((JsonToken)int.MinValue, "test"));
                Assert.AreEqual("token", ex.ParamName);
            }
        }
开发者ID:janky-h,项目名称:Newtonsoft.Json,代码行数:11,代码来源:JsonTextWriterTest.cs

示例13: WriteTokenNullCheck

 public void WriteTokenNullCheck()
 {
     using (JsonWriter jsonWriter = new JsonTextWriter(new StringWriter()))
     {
         ExceptionAssert.Throws<ArgumentNullException>(() => { jsonWriter.WriteToken(null); });
         ExceptionAssert.Throws<ArgumentNullException>(() => { jsonWriter.WriteToken(null, true); });
     }
 }
开发者ID:janky-h,项目名称:Newtonsoft.Json,代码行数:8,代码来源:JsonTextWriterTest.cs

示例14: WriteComments

        public void WriteComments()
        {
            string json = @"//comment*//*hi*/
{//comment
Name://comment
true//comment after true" + StringUtils.CarriageReturn + @"
,//comment after comma" + StringUtils.CarriageReturnLineFeed + @"
""ExpiryDate""://comment" + StringUtils.LineFeed + @"
new
" + StringUtils.LineFeed +
                  @"Constructor
(//comment
null//comment
),
        ""Price"": 3.99,
        ""Sizes"": //comment
[//comment

          ""Small""//comment
]//comment
}//comment 
//comment 1 ";

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

            StringWriter sw = new StringWriter();
            JsonTextWriter w = new JsonTextWriter(sw);
            w.Formatting = Formatting.Indented;

            w.WriteToken(r, true);

            StringAssert.AreEqual(@"/*comment*//*hi*/*/{/*comment*/
  ""Name"": /*comment*/ true/*comment after true*//*comment after comma*/,
  ""ExpiryDate"": /*comment*/ new Constructor(
    /*comment*/,
    null
    /*comment*/
  ),
  ""Price"": 3.99,
  ""Sizes"": /*comment*/ [
    /*comment*/
    ""Small""
    /*comment*/
  ]/*comment*/
}/*comment *//*comment 1 */", sw.ToString());
        }
开发者ID:ZhouAnPing,项目名称:Mail,代码行数:46,代码来源:JsonTextWriterTest.cs

示例15: TransformToSDataPayload

        private async Task TransformToSDataPayload(Stream targetStream)
        {
            using (var oContentStream = await originalContent.ReadAsStreamAsync())
            {
                JsonReader reader = null;
                JsonWriter outStream = null;
                int level = -1;
                try
                {
                    reader = new JsonTextReader(new StreamReader(oContentStream));
                    outStream = new JsonTextWriter(new StreamWriter(targetStream));

                    int respContentType = GetContentType();
                    bool searchForCollection = respContentType == ContentOdataCollection
                                               || respContentType == ContentApiCollection;

                    while (reader.Read())
                    {
                        if (searchForCollection && level == 0 && reader.TokenType == JsonToken.PropertyName)
                        {
                            if ((string)reader.Value == ParamCollectionNameApi || (string)reader.Value == ParamCollectionNameOdata)
                            {
                                WritePagingProperties(outStream);
                                outStream.WritePropertyName(ParamCollectionNameSdata);
                            }
                            else if ((string)reader.Value == ParamTotalresultOdata)
                                outStream.WritePropertyName(ParamTotalresultSdata);
                            else
                                outStream.WriteToken(reader, false);
                        }
                        else if (reader.TokenType == JsonToken.PropertyName)
                            outStream.WritePropertyName(CallOptionalMaps((string)reader.Value));
                        else
                        {
                            if (reader.TokenType == JsonToken.StartObject)
                                level++;
                            else if (reader.TokenType == JsonToken.EndObject)
                                level--;
                            outStream.WriteToken(reader, false);
                        }
                    }
                    outStream.Flush();
                }
                catch (Exception e)
                {
                    // TODO can we get the user and tenant context from here?
                }
                finally
                {
                    if (reader != null)
                        reader.Close();
                    if (outStream != null)
                        outStream.Close();

                }
            }
        }
开发者ID:jaretts,项目名称:ODataSDataDemo,代码行数:57,代码来源:SDataContent.cs


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