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


C# IO.JsonWriterSettings类代码示例

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


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

示例1: TestIndentedTwoElements

 public void TestIndentedTwoElements() {
     BsonDocument document = new BsonDocument() { { "a", "x" }, { "b", "y" } };
     var settings = new JsonWriterSettings { Indent = true };
     string json = document.ToJson(settings);
     string expected = "{\r\n  \"a\" : \"x\",\r\n  \"b\" : \"y\"\r\n}";
     Assert.AreEqual(expected, json);
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:7,代码来源:JsonWriterTests.cs

示例2: TestInt64TenGen

 public void TestInt64TenGen() {
     var document = new BsonDocument { { "a", 1L } };
     var settings = new JsonWriterSettings { OutputMode = JsonOutputMode.TenGen };
     var json = document.ToJson(settings);
     var expected = "{ 'a' : NumberLong(1) }".Replace("'", "\"");
     Assert.AreEqual(expected, json);
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:7,代码来源:JsonWriterTests.cs

示例3: TestIndentedEmptyDocument

 public void TestIndentedEmptyDocument() {
     BsonDocument document = new BsonDocument();
     var settings = new JsonWriterSettings { Indent = true };
     string json = document.ToJson(settings);
     string expected = "{ }";
     Assert.AreEqual(expected, json);
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:7,代码来源:JsonWriterTests.cs

示例4: WriteJson

 public override void WriteJson(Newtonsoft.Json.JsonWriter writer, object value, JsonSerializer serializer)
 {
     //value = ObjectId.GenerateNewId();
     var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
     JObject b = JObject.Parse(value.ToJson(jsonWriterSettings));
     serializer.Serialize(writer, b);
 }
开发者ID:jemc771,项目名称:MongoREST,代码行数:7,代码来源:ObjectIdConverter.cs

示例5: ExportToJson

 /// <summary>
 ///     导出到JSON
 /// </summary>
 /// <param name="dataList"></param>
 /// <param name="filename"></param>
 /// <param name="settings"></param>
 private static void ExportToJson(List<BsonDocument> dataList, string filename, JsonWriterSettings settings)
 {
     var file = new FileStream(filename, FileMode.Create);
     var sw = new StreamWriter(file);
     sw.Write(dataList.ToJson(settings));
     sw.Flush();
 }
开发者ID:magicdict,项目名称:MongoCola,代码行数:13,代码来源:ExportImport.cs

示例6: TraceHtmlReader_v2

        public static void TraceHtmlReader_v2(string file, string traceFile, bool disableScriptTreatment = false, bool useReadAttributeValue_v2 = false)
        {
            try
            {
                __srTraceHtmlReader = zFile.CreateText(traceFile);
                __traceJsonSettings = new JsonWriterSettings();
                __traceJsonSettings.Indent = true;

                using (StreamReader sr = zfile.OpenText(file))
                {
                    HtmlReader_v2 htmlReader = new HtmlReader_v2(sr);
                    htmlReader.Trace = TraceHtmlReader;
                    htmlReader.DisableScriptTreatment = disableScriptTreatment;
                    htmlReader.UseReadAttributeValue_v2 = useReadAttributeValue_v2;
                    htmlReader.ReadAll();
                }
            }
            finally
            {
                if (__srTraceHtmlReader != null)
                {
                    __srTraceHtmlReader.Close();
                    __srTraceHtmlReader = null;
                }
                __traceJsonSettings = null;
            }

        }
开发者ID:labeuze,项目名称:source,代码行数:28,代码来源:TestUnit_HtmlToXml.cs

示例7: TestIndentedOneElement

 public void TestIndentedOneElement() {
     BsonDocument document = new BsonDocument() { { "name", "value" } };
     var settings = new JsonWriterSettings { Indent = true };
     string json = document.ToJson(settings);
     string expected = "{\r\n  \"name\" : \"value\"\r\n}";
     Assert.AreEqual(expected, json);
 }
开发者ID:ebix,项目名称:mongo-csharp-driver,代码行数:7,代码来源:JsonWriterTests.cs

示例8: JsonWriter

 // constructors
 /// <summary>
 /// Initializes a new instance of the JsonWriter class.
 /// </summary>
 /// <param name="writer">A TextWriter.</param>
 /// <param name="settings">Optional JsonWriter settings.</param>
 public JsonWriter(TextWriter writer, JsonWriterSettings settings)
     : base(settings)
 {
     _textWriter = writer;
     _jsonWriterSettings = settings; // already frozen by base class
     _context = new JsonWriterContext(null, ContextType.TopLevel, "");
     State = BsonWriterState.Initial;
 }
开发者ID:abel,项目名称:sinan,代码行数:14,代码来源:JsonWriter.cs

示例9: JsonWriter

 /// <summary>
 /// Initializes a new instance of the JsonWriter class.
 /// </summary>
 /// <param name="writer">A TextWriter.</param>
 /// <param name="settings">Optional JsonWriter settings.</param>
 public JsonWriter(
     TextWriter writer,
     JsonWriterSettings settings
 ) {
     this.textWriter = writer;
     this.settings = settings.Freeze();
     context = new JsonWriterContext(null, ContextType.TopLevel, "");
     state = BsonWriterState.Initial;
 }
开发者ID:dalinhuang,项目名称:tdcodes,代码行数:14,代码来源:JsonWriter.cs

示例10: JsonTraceDataWriter

 public JsonTraceDataWriter(string file, FileOption option, Encoding encoding = null, JsonWriterSettings settings = null)
 {
     file = file.zRootPath(zapp.GetAppDirectory());
     if (option == FileOption.IndexedFile)
         file = zfile.GetNewIndexedFileName(zPath.GetDirectoryName(file), zPath.GetFileName(file));
     //_streamWriter = zFile.CreateText(file);
     Open(file, encoding, option != FileOption.RazFile);
     _closeStreamWriter = true;
     InitSettings(settings);
 }
开发者ID:labeuze,项目名称:source,代码行数:10,代码来源:JsonTraceDataWriterIndexedFile.cs

示例11: Get

        // GET api/values/5
        public string Get(string id)
        {
            rvService svc = new rvService(getMongoDB());
            DataTableParamModel para = new DataTableParamModel();
            para.sDate =Convert.ToDateTime(id);
            var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };

            string rtn = svc.Read(para).ToJson(jsonWriterSettings);
            //rtn = "{\"data\":" + rtn + "}";
            return rtn;
        }
开发者ID:ygkrose,项目名称:reviewportal,代码行数:12,代码来源:reviewController.cs

示例12: GetAsync

        // GET api/Categories/5
        public async Task<string> GetAsync(string id)
        {
            MongoHelper<PaymentType> paymentTypeHelper = new MongoHelper<PaymentType>();
            var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };

            PaymentType paymentType = await paymentTypeHelper.Collection
                .Find(p => p.Id.Equals(ObjectId.Parse(id))) // TODO filter by userId
                .FirstAsync();

            return paymentType.ToJson(jsonWriterSettings);

        }
开发者ID:jaimemorais,项目名称:ExpenseTracker,代码行数:13,代码来源:PaymentTypesController.cs

示例13: GetAsync

        // GET api/Categories/5
        public async Task<string> GetAsync(string id)
        {
            MongoHelper<Category> categoryHelper = new MongoHelper<Category>();
            var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
            
            Category cat = await categoryHelper.Collection
                .Find(c => c.Id.Equals(ObjectId.Parse(id))) // TODO filter by userId
                .FirstAsync(); 

            return cat.ToJson(jsonWriterSettings);
            
        }
开发者ID:jaimemorais,项目名称:ExpenseTracker,代码行数:13,代码来源:CategoriesController.cs

示例14: JsonWriter

        /// <summary>
        /// Initializes a new instance of the JsonWriter class.
        /// </summary>
        /// <param name="writer">A TextWriter.</param>
        /// <param name="settings">Optional JsonWriter settings.</param>
        public JsonWriter(TextWriter writer, JsonWriterSettings settings)
            : base(settings)
        {
            if (writer == null)
            {
                throw new ArgumentNullException("writer");
            }

            _textWriter = writer;
            _jsonWriterSettings = settings; // already frozen by base class
            _context = new JsonWriterContext(null, ContextType.TopLevel, "");
            State = BsonWriterState.Initial;
        }
开发者ID:fir3pho3nixx,项目名称:mongo-csharp-driver,代码行数:18,代码来源:JsonWriter.cs

示例15: aggregateCountryNumberOfIndustrySortedDesc

 //Retourne les indices d'un pays donné trié par un champ par exemple le prix, le volume, market cap etc...
 public Dictionary<string, int> aggregateCountryNumberOfIndustrySortedDesc(string _country)
 {
     Dictionary<string, int> dictionnary = new Dictionary<string, int>();
     var aggregate = collection.Aggregate()
                               .Match(new BsonDocument { { "Country", _country } })
                               .Group(new BsonDocument { { "_id", new BsonDocument { { "Industry", "$Industry" } } }, { "number", new BsonDocument { { "$sum", 1 } } } })
                               .Sort(new BsonDocument { { "number", -1 } }).ToListAsync().Result;
     var jsonSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
     foreach (BsonDocument bsd in aggregate)
     {
         dictionnary.Add(bsd.GetValue("_id").ToBsonDocument().GetValue("Industry").ToString(),Convert.ToInt32(bsd.GetValue("number")));
     }
     return dictionnary;
 }
开发者ID:NicolasGH,项目名称:Projet_final_NoSql,代码行数:15,代码来源:MongoDBClient.cs


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