本文整理汇总了C#中BsonArray.ToJson方法的典型用法代码示例。如果您正苦于以下问题:C# BsonArray.ToJson方法的具体用法?C# BsonArray.ToJson怎么用?C# BsonArray.ToJson使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类BsonArray
的用法示例。
在下文中一共展示了BsonArray.ToJson方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FilterArray
public void FilterArray()
{
var bsonArray = new BsonArray {5, BsonDocument.Parse("{'a':2}")};
bsonArray.Filter((e, v) => e == "[].a");
var expected = new BsonArray {BsonDocument.Parse("{'a':2}")};
Assert.That(expected.ToJson(), Is.EqualTo(bsonArray.ToJson()));
}
示例2: TestAddArrayListWithTwoEntries
public void TestAddArrayListWithTwoEntries()
{
var arrayList = new ArrayList { 1, 2 };
var array = new BsonArray(arrayList);
var json = array.ToJson();
var expected = "[1, 2]".Replace("'", "\"");
Assert.AreEqual(expected, json);
}
示例3: TestAddArrayListWithOneEntry
public void TestAddArrayListWithOneEntry()
{
var arrayList = new ArrayList { 1 };
var array = new BsonArray(arrayList);
var json = array.ToJson();
var expected = "[1]".Replace("'", "\"");
Assert.Equal(expected, json);
}
示例4: ConvertTreeViewTozTreeJson
/// <summary>
///
/// </summary>
/// <param name="tree"></param>
/// <returns></returns>
public static String ConvertTreeViewTozTreeJson(TreeView tree)
{
BsonArray array = new BsonArray();
foreach (TreeNode item in tree.Nodes)
{
array.Add(ConvertTreeNodeTozTreeBsonDoc(item));
}
return array.ToJson(SystemManager.JsonWriterSettings);
}
示例5: ConvertTreeViewTozTreeJson
/// <summary>
/// </summary>
/// <param name="tree"></param>
/// <returns></returns>
public static String ConvertTreeViewTozTreeJson(TreeView tree)
{
var array = new BsonArray();
foreach (TreeNode item in tree.Nodes)
{
array.Add(ConvertTreeNodeTozTreeBsonDoc(item));
}
return array.ToJson(MongoUtility.Basic.Utility.JsonWriterSettings);
}
示例6: GetCollectionzTreeJSON
/// <summary>
/// </summary>
/// <returns></returns>
public static string GetCollectionzTreeJSON(MongoServer mServer)
{
//获得数据
WebDataViewInfo.LimitCnt = 100;
List<BsonDocument> dataList = ViewHelper.GetDataList(ref WebDataViewInfo, mServer);
string collectionName =
Common.Utility.GetTagData(WebDataViewInfo.strDBTag).Split("/".ToCharArray())[(int)EnumMgr.PathLv.CollectionLv];
var tree = new ctlTreeViewColumns();
UIHelper.FillDataToTreeView(collectionName, tree, dataList, WebDataViewInfo.SkipCnt);
var array = new BsonArray();
foreach (TreeNode item in tree.TreeView.Nodes) {
array.Add(ConvertTreeNodeTozTreeBsonDoc(item));
}
return array.ToJson(MongoUtility.Basic.Utility.JsonWriterSettings);
}
示例7: GetCollectionzTreeJSON
/// <summary>
/// </summary>
/// <returns></returns>
public static String GetCollectionzTreeJSON()
{
//获得数据
WebDataViewInfo.LimitCnt = 100;
List<BsonDocument> dataList = GetDataList(ref WebDataViewInfo);
String collectionName =
SystemManager.GetTagData(WebDataViewInfo.strDBTag).Split("/".ToCharArray())[(int) PathLv.CollectionLv];
var tree = new TreeViewColumns();
FillDataToTreeView(collectionName, tree, dataList, WebDataViewInfo.SkipCnt);
var array = new BsonArray();
foreach (TreeNode item in tree.TreeView.Nodes)
{
array.Add(UIHelper.ConvertTreeNodeTozTreeBsonDoc(item));
}
return array.ToJson(SystemManager.JsonWriterSettings);
;
}
示例8: get_stock_test
public string get_stock_test()
{
TimeSpan span = DateTime.Now - new System.DateTime(1970, 1, 1);
Random randm = new Random();
BsonDocument doc = new BsonDocument();
BsonArray datas = new BsonArray();
BsonArray data1 = new BsonArray();
for (int i = 1; i < 200; i++)
{
BsonArray data_item = new BsonArray();
data_item.Add((Math.Round(span.TotalSeconds) + i).ToString() + "000");
data_item.Add(1000+randm.Next(100));
data1.Add(data_item);
}
BsonArray data2 = new BsonArray();
for (int i = 1; i < 200; i++)
{
BsonArray data_item = new BsonArray();
data_item.Add((Math.Round(span.TotalSeconds) + i).ToString() + "000");
data_item.Add(900+randm.Next(10));
data2.Add(data_item);
}
BsonDocument doc_data1 = new BsonDocument();
doc_data1.Add("name", "Trade");
doc_data1.Add("data", data1);
BsonDocument doc_data2 = new BsonDocument();
doc_data2.Add("name", "China");
doc_data2.Add("data", data2);
datas.Add(doc_data1);
datas.Add(doc_data2);
return datas.ToJson();
}
示例9: get_stock
public string get_stock()
{
string sql = "";
string[] websites = new string[] { "btce", "okcoin", "btcchina" };
double rate = CurrencyHelper.get_rate("usd", "cny");
BsonArray datas = new BsonArray();
foreach (string website in websites)
{
BsonDocument doc = new BsonDocument();
doc.Add("name", website);
BsonArray data = new BsonArray();
sql = "select * from ticker_log where currency like '%btc%' and website='{0}'";
sql = string.Format(sql, website);
DataTable dt = SQLServerHelper.get_table(sql);
foreach (DataRow row in dt.Rows)
{
DateTime date = Convert.ToDateTime(row["timespan"].ToString().Substring(0, 19));
TimeSpan span = date - new System.DateTime(1970, 1, 1);
BsonArray data_item = new BsonArray();
data_item.Add(Math.Round(span.TotalSeconds).ToString() + "000");
if (row["currency"].ToString().Contains("usd"))
{
data_item.Add(Math.Round(Convert.ToDouble(row["last"].ToString()) * rate, 2));
}
else
{
data_item.Add(Convert.ToDouble(row["last"].ToString()));
}
data.Add(data_item);
}
doc.Add("data", data);
datas.Add(doc);
}
return datas.ToJson();
}
示例10: GetCaseFilter
/// <summary>
/// 获取过滤选项
/// </summary>
/// <param name="ReceiveMessage">回调消息</param>
public void GetCaseFilter(BsonDocument ReceiveMessage)
{
BsonArray TreeArray = new BsonArray();
BsonDocument Case = cs.FindOne(new BsonDocument("CaseName", CaseInfo.CaseName));
BsonDocument DirTreeDoc = new BsonDocument();
DirTreeDoc.Add("text", "目录结构");
DirTreeDoc.Add("children", new BsonArray().Add(Case.GetValue("MailPath")));
TreeArray.Add(DirTreeDoc);
BsonDocument FileTypeTreeDoc = new BsonDocument();
FileTypeTreeDoc.Add("text", "文件类型");
BsonArray FileTypeArray = new BsonArray();
foreach (BsonElement elm in Case.GetValue("FileType").AsBsonDocument)
{
FileTypeArray.Add(new BsonDocument("text", elm.Name).Add("Count", elm.Value));
}
FileTypeTreeDoc.Add("children", new BsonArray(FileTypeArray.OrderBy(t => -t.AsBsonDocument["Count"].AsInt32)));
TreeArray.Add(FileTypeTreeDoc);
BsonDocument MailAddressDoc = new BsonDocument();
MailAddressDoc.Add("text", "邮件地址");
BsonArray MailAddressArray = new BsonArray();
foreach (BsonDocument MailAddress in mas.GetDataForCase(new BsonDocument("ForCase", CaseInfo.CaseName)))
{
BsonDocument Address = new BsonDocument();
Address.Add("text", MailAddress.GetValue("Address"));
Address.Add("Count", MailAddress.GetValue("RepeatTimes"));
Address.Add("searchKey", "Address");
Address.Add("searchValue", MailAddress.GetValue("_id"));
MailAddressArray.Add(Address);
}
MailAddressDoc.Add("children", new BsonArray(MailAddressArray.OrderBy(t => -t.AsBsonDocument["Count"].AsInt32)));
TreeArray.Add(MailAddressDoc);
BsonDocument IpDoc = new BsonDocument();
IpDoc.Add("text", "Ip地址");
BsonArray IpArray = new BsonArray();
foreach (BsonDocument Ip in ips.GetDataForCase(new BsonDocument("ForCase", CaseInfo.CaseName)))
{
IpArray.Add(new BsonDocument("text", Ip.GetValue("Ip")).Add("Count", Ip.GetValue("RepeatTimes")));
}
IpDoc.Add("children", new BsonArray(IpArray.OrderBy(t => -t.AsBsonDocument["Count"].AsInt32)));
TreeArray.Add(IpDoc);
BsonDocument ContainerDoc = new BsonDocument();
ContainerDoc.Add("text", "集装箱编号");
BsonArray ContainerArray = new BsonArray();
foreach (BsonDocument Container in cos.GetData(new BsonDocument("ForCase", CaseInfo.CaseName)))
{
ContainerArray.Add(new BsonDocument("text", Container.GetValue("Container")).Add("Count", Container.GetValue("RepeatTimes")));
}
ContainerDoc.Add("children", new BsonArray(ContainerArray.OrderBy(t => -t.AsBsonDocument["Count"].AsInt32)));
TreeArray.Add(ContainerDoc);
BsonDocument NickNameDoc = new BsonDocument();
NickNameDoc.Add("text", "昵称");
BsonArray NickNameArray = new BsonArray();
foreach (BsonDocument NickName in nns.GetData(new BsonDocument("ForCase", CaseInfo.CaseName)))
{
NickNameArray.Add(new BsonDocument("text", NickName.GetValue("NickName")).Add("Count", NickName.GetValue("RepeatTimes")));
}
NickNameDoc.Add("children", new BsonArray(NickNameArray.OrderBy(t => -t.AsBsonDocument["Count"].AsInt32)));
TreeArray.Add(NickNameDoc);
BsonDocument PhoneDoc = new BsonDocument();
PhoneDoc.Add("text", "电话号码");
BsonArray PhoneArray = new BsonArray();
foreach (BsonDocument Phone in ps.GetData(new BsonDocument("ForCase", CaseInfo.CaseName)))
{
PhoneArray.Add(new BsonDocument("text", Phone.GetValue("Phone")).Add("Count", Phone.GetValue("RepeatTimes")));
}
PhoneDoc.Add("children", new BsonArray(PhoneArray.OrderBy(t => -t.AsBsonDocument["Count"].AsInt32)));
TreeArray.Add(PhoneDoc);
ReceiveMessage.Add("StateCode", 0);
ReceiveMessage.Add("ReData", TreeArray.ToJson(jsonSettings));
CallBack();
}
示例11: get_analyse_depth_stock
public string get_analyse_depth_stock(string time)
{
string sql = "";
string[] websites = new string[] { "btcchina"};
double rate = CurrencyHelper.get_rate("usd", "cny");
BsonArray datas = new BsonArray();
foreach (string website in websites)
{
BsonDocument doc = new BsonDocument();
doc.Add("name", website);
BsonArray data = new BsonArray();
if (website == "btcchina")
{
sql = "select top 10020 * from trade_btcchina where time >={0} order by id";
sql = string.Format(sql, time);
DataTable dt = SQLServerHelper.get_table(sql);
foreach (DataRow row in dt.Rows)
{
BsonArray data_item = new BsonArray();
data_item.Add(row["time"].ToString());
if (row["currency"].ToString().Contains("usd"))
{
data_item.Add(Math.Round(Convert.ToDouble(row["price"].ToString()) * rate, 2));
}
else
{
data_item.Add(Convert.ToDouble(row["price"].ToString()));
}
data.Add(data_item);
}
}
doc.Add("data", data);
datas.Add(doc);
}
return datas.ToJson();
}
示例12: get_stock
public string get_stock()
{
string sql = "";
string[] websites = new string[] { "btcchina", "huobi", "okcoin_cn" };
double rate = CurrencyHelper.get_rate("usd", "cny");
BsonArray datas = new BsonArray();
foreach (string website in websites)
{
BsonDocument doc = new BsonDocument();
doc.Add("name", website);
BsonArray data = new BsonArray();
sql = " select * " +
" from (select top 1002 * from ticker_log where currency like '%btc%' and website='{0}' order by id desc) a" +
" order by id ";
sql = string.Format(sql, website);
DataTable dt = SQLServerHelper.get_table(sql);
foreach (DataRow row in dt.Rows)
{
BsonArray data_item = new BsonArray();
data_item.Add(row["timespan"].ToString());
if (row["currency"].ToString().Contains("usd"))
{
data_item.Add(Math.Round(Convert.ToDouble(row["last"].ToString()) * rate, 2));
}
else
{
data_item.Add(Convert.ToDouble(row["last"].ToString()));
}
data.Add(data_item);
}
doc.Add("data", data);
datas.Add(doc);
}
return datas.ToJson();
}