本文整理汇总了C#中Newtonsoft.Json.Linq.JArray.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# JArray.ToString方法的具体用法?C# JArray.ToString怎么用?C# JArray.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Newtonsoft.Json.Linq.JArray
的用法示例。
在下文中一共展示了JArray.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatPropertyInJson
public void FormatPropertyInJson()
{
JObject query = new JObject();
JProperty orderProp = new JProperty("order", "breadth_first");
query.Add(orderProp);
JObject returnFilter = new JObject();
returnFilter.Add("body", new JValue("position.endNode().getProperty('name').toLowerCase().contains('t')"));
returnFilter.Add("language", new JValue("javascript"));
query.Add("return_filter", new JValue(returnFilter.ToString()));
JObject pruneEval = new JObject();
pruneEval.Add("body", new JValue("position.length() > 10"));
pruneEval.Add("language", new JValue("javascript"));
query.Add("prune_evaluator", pruneEval.ToString());
query.Add("uniqueness", new JValue("node_global"));
JArray relationships = new JArray();
JObject relationShip1 = new JObject();
relationShip1.Add("direction", new JValue("all"));
relationShip1.Add("type", new JValue("knows"));
relationships.Add(relationShip1);
JObject relationShip2 = new JObject();
relationShip2.Add("direction", new JValue("all"));
relationShip2.Add("type", new JValue("loves"));
relationships.Add(relationShip2);
query.Add("relationships", relationships.ToString());
//arr.Add(
Console.WriteLine(query.ToString());
//Assert.AreEqual(@"""order"" : ""breadth_first""", jobject.ToString());
}
示例2: Save
private void Save()
{
JArray array = new JArray();
foreach(Control c in Page.Form.Controls){
if(c is TextBox){
TextBox tb = (TextBox) c;
if(!tb.Text.IsNullOrEmpty()){
array.Add(JObject.Parse("{\"id\":\"" + tb.ID + "\",\"value\":\"" + tb.Text.Trim() + "\"}"));
}
}
}
if(array.Count > 0){
int did = Request["did"].ToInt32();
FormData model = service.GetFormData(did,FormType.LQHHLJL);
if(model != null){
model.formdata = array.ToString();
service.UpdateFormData(model);
}
else{
service.AddFormData(new FormData
{
dataid = did,
formtype = FormType.LQHHLJL,
formdata = array.ToString()
});
}
if(sample != null){
sample.SerialNum = TextBox2.Text.Trim();
sample.JGBW = TextBox9.Text.Trim();
sampleService.UpdateSample(sample);
}
}
}
示例3: ReadAsCollection_ObjectArray
public void ReadAsCollection_ObjectArray()
{
JArray values = new JArray();
for (int i = 1; i <= 3; i++)
{
JObject jsonObject = new JObject
{
{ "prop1", "value1" },
{ "prop2", true },
{ "prop3", 123 }
};
values.Add(jsonObject);
}
string json = values.ToString();
byte[] bytes = Encoding.UTF8.GetBytes(json);
MemoryStream ms = new MemoryStream(bytes);
var result = FunctionBinding.ReadAsCollection(ms).ToArray();
Assert.Equal(3, result.Length);
for (int i = 0; i < 3; i++)
{
JObject jsonObject = (JObject)result[i];
Assert.Equal("value1", (string)jsonObject["prop1"]);
Assert.Equal(true, (bool)jsonObject["prop2"]);
Assert.Equal(123, (int)jsonObject["prop3"]);
}
}
示例4: Run
public async Task Run()
{
// Gather download count data from statistics warehouse
IReadOnlyCollection<DownloadCountData> downloadData;
Trace.TraceInformation("Gathering Download Counts from {0}/{1}...", StatisticsDatabase.DataSource, StatisticsDatabase.InitialCatalog);
using (var connection = await StatisticsDatabase.ConnectTo())
using (var transaction = connection.BeginTransaction(IsolationLevel.Snapshot))
{
downloadData = (await connection.QueryWithRetryAsync<DownloadCountData>(
_storedProcedureName, commandType: CommandType.StoredProcedure, transaction: transaction, commandTimeout: _defaultCommandTimeout)).ToList();
}
Trace.TraceInformation("Gathered {0} rows of data.", downloadData.Count);
if (downloadData.Any())
{
SemanticVersion semanticVersion = null;
// Group based on Package Id
var grouped = downloadData.GroupBy(p => p.PackageId);
var registrations = new JArray();
foreach (var group in grouped)
{
var details = new JArray();
details.Add(group.Key);
foreach (var gv in group)
{
// downloads.v1.json should only contain normalized versions - ignore others
if (SemanticVersion.TryParse(gv.PackageVersion, out semanticVersion)
&& gv.PackageVersion == semanticVersion.ToNormalizedString())
{
var version = new JArray(gv.PackageVersion, gv.TotalDownloadCount);
details.Add(version);
}
}
registrations.Add(details);
}
var reportText = registrations.ToString(Formatting.None);
foreach (var storageContainerTarget in Targets)
{
try
{
var targetBlobContainer = await GetBlobContainer(storageContainerTarget);
var blob = targetBlobContainer.GetBlockBlobReference(ReportName);
Trace.TraceInformation("Writing report to {0}", blob.Uri.AbsoluteUri);
blob.Properties.ContentType = "application/json";
await blob.UploadTextAsync(reportText);
Trace.TraceInformation("Wrote report to {0}", blob.Uri.AbsoluteUri);
}
catch (Exception ex)
{
Trace.TraceError("Error writing report to storage account {0}, container {1}. {2} {3}",
storageContainerTarget.StorageAccount.Credentials.AccountName,
storageContainerTarget.ContainerName, ex.Message, ex.StackTrace);
}
}
}
}
示例5: GetAllTheme
public static string GetAllTheme()
{
JArray ja = new JArray();
try
{
using (venuesEntities db = new venuesEntities())
{
string strSql = "SELECT tt.ID,tt.ThemeImage,tt.ThemeName,tt.Sequence FROM tbl_theme AS tt ORDER BY tt.Sequence";
ObjectQuery<DbDataRecord> kss = db.CreateQuery<DbDataRecord>(strSql);
foreach (var ks in kss)
{
ja.Add(
new JObject(
new JProperty("ID", ks["ID"].ToString()),
new JProperty("ThemeImage", ks["ThemeImage"].ToString()),
new JProperty("Sequence", ks["Sequence"].ToString()),
new JProperty("ThemeName", ks["ThemeName"].ToString())
)
);
};
}
}
catch (Exception e)
{
// LogManager.addLog(KeyManager.LogTypeId_Error, KeyManager.MENUS.Menu_SalesManager, "查询所有主题,error=" + e.Message, loginUserInfo);
}
return ja.ToString();
}
示例6: BatchAsync
/// <summary>
/// Begins the async batch operation
/// </summary>
/// <param name="commandDatas">The command data.</param>
/// <returns></returns>
public Task<BatchResult[]> BatchAsync(ICommandData[] commandDatas)
{
var metadata = new JObject();
AddTransactionInformation(metadata);
var req = HttpJsonRequest.CreateHttpJsonRequest(this, url + "/bulk_docs", "POST", metadata, credentials);
var jArray = new JArray(commandDatas.Select(x => x.ToJson()));
var data = Encoding.UTF8.GetBytes(jArray.ToString(Formatting.None));
return Task.Factory.FromAsync(req.BeginWrite, req.EndWrite, data, null)
.ContinueWith(writeTask => Task.Factory.FromAsync<string>(req.BeginReadResponseString, req.EndReadResponseString,null))
.Unwrap()
.ContinueWith(task =>
{
string response;
try
{
response = task.Result;
}
catch (WebException e)
{
var httpWebResponse = e.Response as HttpWebResponse;
if (httpWebResponse == null ||
httpWebResponse.StatusCode != HttpStatusCode.Conflict)
throw;
throw ThrowConcurrencyException(e);
}
return JsonConvert.DeserializeObject<BatchResult[]>(response);
});
}
示例7: StartAsyncRequest
public async Task<string> StartAsyncRequest(string url) {
//lookup user and convert all their feed items into json
//HACK CAUTION: fragile, screen_name is last param so we can do this as long as it doesn't change
string account = url.Split('=').Last();
var items = Data.feeditems[account];
var ja = new JArray();
foreach (var i in items) {
var jo = new JObject();
jo["user"] = new JObject {["screen_name"] = i.account};;
jo["created_at"] = i.createdAt.ToString(TwitterFeedItemService.twitterDateTimeFormat);
jo["id"] = i.id;
jo["text"] = i.text;
var m = new JArray();
for (int j = 1; j <= i.mentions; j++) {
m.Add("mention");
}
jo["entities"] = new JObject {["user_mentions"] = m};
ja.Add(jo);
}
var t = new Task<string>(() => ja.ToString());
t.Start();
return await t;
}
示例8: button_send_Tapped
private async void button_send_Tapped(object sender, Windows.UI.Xaml.Input.TappedRoutedEventArgs e)
{
JArray ja = new JArray();
foreach (var a in ((ListView)listView_friends).SelectedItems)
{
classes.Friend friendToSendSnapTo = (classes.Friend)(a);
ja.Add(friendToSendSnapTo.username);
}
String JSON = await a.sendSnap(main.static_user, main.static_pass, pb, ja.ToString(), snap_file, int.Parse(slider_time.Value.ToString()));
//Frame.Navigate(typeof(snap_screen));
JObject jo = JObject.Parse(JSON);
if (jo["status"].ToString() == "True")
{
h.showSingleButtonDialog("Snap uploaded", "Snap uploaded successfully!", "Dismiss");
}
else
{
h.showSingleButtonDialog("Server error [" + jo["code"] + "]", ((jo["message"] != null) ? jo["message"].ToString() : "No server message was provided"), "Dismiss");
}
}
示例9: GetPropertyEditors
/// <summary>
/// Parse the property editors from the json array
/// </summary>
/// <param name="jsonEditors"></param>
/// <returns></returns>
internal static IEnumerable<PropertyEditor> GetPropertyEditors(JArray jsonEditors)
{
return JsonConvert.DeserializeObject<IEnumerable<PropertyEditor>>(
jsonEditors.ToString(),
new PropertyEditorConverter(),
new PreValueFieldConverter());
}
示例10: SplitShowsByGenre
public static Tuple<string, string> SplitShowsByGenre(string json, string genre)
{
JArray selectedShowsJson = new JArray();
JArray otherShowsJson = new JArray();
foreach (JObject showJson in JArray.Parse(json))
{
bool genreFound = false;
foreach (JValue genreJson in showJson.Value<JArray>("genres"))
{
if (genreJson.ToString() == genre)
{
selectedShowsJson.Add(showJson);
genreFound = true;
break;
}
}
if (!genreFound)
{
otherShowsJson.Add(showJson);
}
}
return new Tuple<string, string>(selectedShowsJson.ToString(Formatting.None), otherShowsJson.ToString(Formatting.None));
}
示例11: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
if (Request["odds"] != null)
{
string[] oddsArray = Request["odds"].Split('|');
DataTable dt = this.FillOddsHistory(oddsArray);//填充
DateTime stime = Convert.ToDateTime(dt.Compute("max(time)", "")).AddHours(-6);// 6小时内
dt = dt.Select("time > '" + stime.ToString() + "'").CopyToDataTable();
JArray data = new JArray();
foreach (DataRow dr in dt.Rows)
{
DataSet ds = scheduleBLL.statOddsHistory("companyid=" + oddsArray[0] + " and e_win=" + dr["odds_w"] +
" and e_draw=" + dr["odds_d"] + " and e_lost=" + dr["odds_l"]);
if (Convert.ToInt32(ds.Tables[0].Rows[0]["totalcount"]) > 0)
{
JObject obj = new JObject();
obj.Add("time", dr["time"].ToString());
obj.Add("win", Convert.ToDecimal(ds.Tables[0].Rows[0]["perwin"]) - Convert.ToDecimal(dr["per_w"]) * 100);
obj.Add("draw", Convert.ToDecimal(ds.Tables[0].Rows[0]["perdraw"]) - Convert.ToDecimal(dr["per_d"]) * 100);
obj.Add("lost", Convert.ToDecimal(ds.Tables[0].Rows[0]["perlost"]) - Convert.ToDecimal(dr["per_l"]) * 100);
obj.Add("totalcount", Convert.ToInt32(ds.Tables[0].Rows[0]["totalcount"]));
data.Add(obj);
}
}
Response.Write(data.ToString());
Response.End();
}
}
}
示例12: GetPageContentByPageId
public static string GetPageContentByPageId(int pageId, string loginUserInfo)
{
JArray ja = new JArray();
try
{
using (venuesEntities db = new venuesEntities())
{
string strSql = string.Format("SELECT tpc.ContentSequence,tpc.ContentValue,tpc.ID,tpc.ModuleID,tpc.PageID,tpc.TemplateID ,tm.ModuleType FROM tbl_page_content AS tpc LEFT JOIN tbl_module AS tm ON tm.ID=tpc.ModuleID WHERE tpc.PageID= {0}", pageId);
ObjectQuery<DbDataRecord> kss = db.CreateQuery<DbDataRecord>(strSql);
string path = System.Configuration.ConfigurationManager.AppSettings["FilePath"].ToString();
foreach (var ks in kss)
{
ja.Add(
new JObject(
new JProperty("ID", ks["ID"].ToString()),
new JProperty("ContentSequence", ks["ContentSequence"].ToString()),
new JProperty("ContentValue", ks["ContentValue"].ToString()),
new JProperty("FileNameServer", ks["ContentValue"].ToString()),
new JProperty("ModuleID", ks["ModuleID"].ToString()),
new JProperty("ModuleTypeID", ks["ModuleType"].ToString()),
new JProperty("PageID", ks["PageID"].ToString()),
new JProperty("TemplateID", ks["TemplateID"].ToString())
// new JProperty("FilePathAddress", path)
)
);
};
}
}
catch (Exception e)
{
LogManager.addLog(KeyManager.LogTypeId_Error, KeyManager.MENUS.Menu_PagesManager, "根据pageId获取该页面内容信息:" + e.Message, loginUserInfo);
}
return ja.ToString();
}
示例13: AddAdditionalResults
public RestResponse AddAdditionalResults(int monitorId, JArray jsArray, long checktime)
{
var parameters = new Dictionary<String, Object>();
parameters.Add("monitorId", monitorId);
parameters.Add("results", jsArray.ToString());
parameters.Add("checktime", checktime);
return MakePostRequest(CustomMonitoraction.addAdditionalResults, parameters);
}
示例14: List
public IActionResult List()
{
JArray names = new JArray(
from name in FileAccess.GetVenueNames()
select new JValue(name)
);
return Content(names.ToString());
}
示例15: List
public IActionResult List()
{
JArray arr = new JArray(
from name in FileAccess.GetFixtureNames()
select new JValue(name)
);
return Content(arr.ToString());
}