本文整理汇总了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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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;
}
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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;
}