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

C# IO.JsonWriterSettings类代码示例

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

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



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


示例16: aggregateCountrySorted

 //Retourne les indices d'un pays donné trié par un champ par exemple le prix, le volume, market cap etc...
 public List<Stockobject> aggregateCountrySorted(string _country, string _sortBy, bool _asc)
 {
     int i = 0;
     if (_asc) i = 1;
     else i = -1;
     List<Stockobject> list = new List<Stockobject>();
     var aggregate = collection.Aggregate()
                               .Match(new BsonDocument { { "Country", _country } })
                               .Sort(new BsonDocument { { _sortBy, i } }).ToListAsync().Result;
     var jsonSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
     foreach (BsonDocument bsd in aggregate)
     {
         list.Add(BsonSerializer.Deserialize<Stockobject>(bsd.ToJson()));
     }
     return list;
 }
开发者ID:NicolasGH,项目名称:Projet_final_NoSql,代码行数:17,代码来源:MongoDBClient.cs


示例17: GetAsync

        // GET api/ExpenseApi
        public async Task<IEnumerable<string>> GetAsync()
        {            
            MongoHelper<Expense> expenseHelper = new MongoHelper<Expense>();
                
            IList<string> returnList = new List<string>();
            var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
            await expenseHelper.Collection.Find(e => e.Value > 0) // TODO filter by userId
                .ForEachAsync(expenseDocument => 
                {
                    string docJson = expenseDocument.ToJson(jsonWriterSettings);
                    returnList.Add(docJson);
                }
            );                    

            return returnList.ToArray();
        }
开发者ID:jaimemorais,项目名称:ExpenseTracker,代码行数:17,代码来源:ExpenseApiController.cs


示例18: TestDateTime

 public void TestDateTime()
 {
     DateTime jan_1_2010 = new DateTime(2010, 1, 1);
     double expectedValue = (jan_1_2010.ToUniversalTime() - BsonConstants.UnixEpoch).TotalMilliseconds;
     BsonDocument document = new BsonDocument() {
         { "date", jan_1_2010 }
     };
     var settings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
     string json = document.ToJson(settings);
     string expected = "{ \"date\" : { \"$date\" : # } }".Replace("#", expectedValue.ToString());
     Assert.AreEqual(expected, json);
     settings = new JsonWriterSettings { OutputMode = JsonOutputMode.JavaScript };
     json = document.ToJson(settings);
     expected = "{ \"date\" : Date(#) }".Replace("#", expectedValue.ToString());
     Assert.AreEqual(expected, json);
 }
开发者ID:modesto,项目名称:mongo-csharp-driver,代码行数:16,代码来源:JsonWriterTests.cs


示例19: GetAsync

        // GET api/CategoryApi
        public async Task<IEnumerable<string>> GetAsync()
        {
            MongoHelper<Category> categoryHelper = new MongoHelper<Category>();
                
            IList<string> returnList = new List<string>();
            var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };
            await categoryHelper.Collection.Find(e => e.Name != null) // TODO filter by userId
                .ForEachAsync(categoryDocument => 
                {
                    string docJson = categoryDocument.ToJson(jsonWriterSettings);
                    returnList.Add(docJson);
                }
            );

            return returnList.ToArray();
        }
开发者ID:jaimemorais,项目名称:ExpenseTracker,代码行数:17,代码来源:CategoryApiController.cs


示例20: Get

        // GET: api/UserProfiles
        public async Task<HttpResponseMessage> Get(
            [FromUri] string repository,
            [FromUri] string display_name,
            [FromUri] string month
            )
        {
            EasyAnalysis.Framework.ConnectionStringProviders.IConnectionStringProvider mongoDBCSProvider =
                   EasyAnalysis.Framework.ConnectionStringProviders.ConnectionStringProvider.CreateConnectionStringProvider(EasyAnalysis.Framework.ConnectionStringProviders.ConnectionStringProvider.ConnectionStringProviderType.MongoDBConnectionStringProvider);
            var client = new MongoClient(mongoDBCSProvider.GetConnectionString(repository));

            var database = client.GetDatabase(repository);

            var userProfiles = database.GetCollection<BsonDocument>("asker_activities");

            var builder = Builders<BsonDocument>.Filter;

            FilterDefinition<BsonDocument> filter = "{}";

            if (!string.IsNullOrEmpty(display_name))
            {
                filter = filter & builder.Regex("display_name", BsonRegularExpression.Create(new Regex("^" + display_name, RegexOptions.IgnoreCase)));
            }

            if (!string.IsNullOrEmpty(month))
            {
                filter = filter & builder.Eq("month", month);
            }

            var result = await userProfiles
                .Find(filter)
                .Sort("{ total: -1 }")
                .ToListAsync();

            var response = Request.CreateResponse();

            response.StatusCode = HttpStatusCode.OK;

            var jsonWriterSettings = new JsonWriterSettings { OutputMode = JsonOutputMode.Strict };

            response.Content = new StringContent(result.ToJson(jsonWriterSettings), Encoding.UTF8, "application/json");

            return response;
        }
开发者ID:Edward-Zhou,项目名称:easy-analysis,代码行数:44,代码来源:UserProfileController.cs



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
C# Driver.CommandDocument类代码示例发布时间:2022-05-26
下一篇:
C# IO.JsonWriterContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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