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


C# JObject.AsString方法代码示例

本文整理汇总了C#中Newtonsoft.Json.Linq.JObject.AsString方法的典型用法代码示例。如果您正苦于以下问题:C# JObject.AsString方法的具体用法?C# JObject.AsString怎么用?C# JObject.AsString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Newtonsoft.Json.Linq.JObject的用法示例。


在下文中一共展示了JObject.AsString方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Update

 public override void Update(JObject dataOut)
 {
     base.Update(dataOut);
     string name = dataOut.AsString("AccountName");
     Utils.Check(!_keys.Contains(name), "Account {0} has duplicate name", name);
     _keys.Add(name);
     string [] parts = name.Split(':');
     if(parts.Length > 1) {
         string key = parts[parts.Length - 1];
         Utils.Check(!_keys.Contains(key), "Subaccount of {0} has duplicate name {1}", name, key);
         _keys.Add(key);
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:13,代码来源:Importer.cs

示例2: Test

 public override bool Test(JObject data)
 {
     string value = data.AsString(JObjectFieldName);
     switch (_comparison) {
         case Comparison.Empty:
             return string.IsNullOrEmpty(value);
         case Comparison.NonEmpty:
             return !string.IsNullOrEmpty(value);
         case Comparison.Equal:
             return value == _value;
         case Comparison.Contains:
             return value.Contains(_value);
         case Comparison.StartsWith:
             return value.StartsWith(_value);
         case Comparison.EndsWith:
             return value.EndsWith(_value);
         default:
             return true;
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:20,代码来源:Reports.cs

示例3: AuditHistoryPost

 public object AuditHistoryPost(JObject json)
 {
     OriginalMethod = json.AsString("ReportType");
     Method = OriginalMethod.Substring(5).ToLower();
     MethodInfo method = this.GetType().GetMethod(OriginalMethod + "Post", BindingFlags.IgnoreCase | BindingFlags.Public | BindingFlags.Instance);
     Utils.Check(method != null, "Invalid table {0}", Method);
     return method.Invoke(this, new object[] { json });
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:8,代码来源:Reports.cs

示例4: removeRepeatsAndTotal

 /// <summary>
 /// Remove data from certain tables which repeats in a series of records, and add totals as required
 /// </summary>
 /// <param name="tables">List of tables with potentially repeating data</param>
 /// <returns>Modified list</returns>
 IEnumerable<JObject> removeRepeatsAndTotal(IEnumerable<JObject> data, params string[] tables)
 {
     JObject last = null;
     JObject spacer = new JObject().AddRange("@class", "totalSpacer");
     // All fields in the repeating tables
     HashSet<string> flds = new HashSet<string>(tables.SelectMany(t => Database.TableFor(t).Fields.Select(f => f.Name)));
     // Our fields in the repeating tables
     HashSet<string> fields = new HashSet<string>();
     List<string> essentialFields = _fields.Where(f => f.Essential).Select(f => f.Name).ToList();
     foreach (string f in _fields.Where(f => tables.Contains(f.Table)).Select(f => f.Name))
         fields.Add(f);	// One of our fields in a potentially repeating table (need to be at front)
     foreach (string f in flds.Where(f => !fields.Contains(f)))
         fields.Add(f);	// Rest of potentially repeating fields
     string[] sortFields = _sortFields == null ? new string[0] : _sortFields.Where(f => fieldFor(f).Include).ToArray();
     string[] lastTotalBreak = new string[sortFields.Length + 1];
     Dictionary<string, decimal[]> totals = new Dictionary<string, decimal[]>();
     string firstStringField = null;
     if (_total) {
         // Build list of totalling fields
         foreach (ReportField f in _fields) {
             if (!f.Include) continue;
             string type = f.AsString("type");
             if (firstStringField == null && type == "string" && !sortFields.Contains(f.Name))
                 firstStringField = f.Name;
             if (f.Name == "VatRate") continue;
             if (type != "decimal" && type != "double" && type != "credit" && type != "debit") continue;
             totals[f.Name] = new decimal [sortFields.Length + 1];
         }
     }
     // Function to generate total record - index is sort field number (sortFields.length for grand total)
     Func<int, JObject> totalRecord = delegate(int level) {
         JObject t = new JObject().AddRange("@class", "total");
         foreach (string f in totals.Keys.ToList()) {
             t[f] = totals[f][level];
             totals[f][level] = 0;
         }
         if (firstStringField != null)
             t[firstStringField] = level == sortFields.Length ? "Grand Total" : "Total";
         if(level < sortFields.Length)
             t[sortFields[level]] = lastTotalBreak[level];
         lastTotalBreak[level] = null;
         return t;
     };
     foreach (JObject r in data) {
         JObject record = new JObject(r);
         JObject id = null;
         if (essentialFields.Count > 0) {
             // Make recordId object with essential fields (for user click and expand)
             id = new JObject();
             foreach (string f in essentialFields) {
                 id[f] = record[f];
                 if (!fields.Contains(f))
                     record.Remove(f);		// Don't want essential fields to interfere with checking for duplicates
             }
         }
         if (last != null) {
             if (_total) {
                 for (int level = sortFields.Length; level-- > 0; ) {
                     if (record.AsString(sortFields[level]) != lastTotalBreak[level]) {
                         if (lastTotalBreak[level] != null) {
                             // Output totals for this sort field
                             yield return totalRecord(level);
                             yield return spacer;
                         }
                     }
                 }
             }
             // Now remove duplicate fields
             foreach (string f in fields) {
                 if (last.AsString(f) == record.AsString(f))
                     record.Remove(f);
                 else
                     break;
             }
             if (record.IsAllNull())
                 continue;		// Everything repeats - ignore duplicate record
         }
         if(id != null)
             record["recordId"] = id;
         if (_total) {
             // Cache total break values
             for(int level = 0; level < sortFields.Length; level++)
                 lastTotalBreak[level] = r.AsString(sortFields[level]);
             // Accumulate totals
             foreach (string f in totals.Keys.ToList()) {
                 decimal v = record.AsDecimal(f);
                 if (f == "Credit") {
                     v = r.AsDecimal("Amount");
                     v = v < 0 ? -v : 0;
                 } else if (f == "Debit") {
                     v = r.AsDecimal("Amount");
                     if (v < 0) v = 0;
                 }
                 for(int level = 0; level <= sortFields.Length; level++)
                     totals[f][level] += v;
//.........这里部分代码省略.........
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:101,代码来源:Reports.cs

示例5: initialiseReport

 /// <summary>
 /// Set up any report
 /// </summary>
 /// <param name="json">The posted report parameters</param>
 void initialiseReport(JObject json)
 {
     string reportType = OriginalMethod.ToLower().Replace("post", "");
     Utils.Check(json.AsString("ReportType").ToLower() == reportType, "Invalid report type");
     dynamic r = SessionData.Report;
     if(r == null)
         SessionData.Report = r = new JObject();
     r.reportType = json;
     _fields = new List<ReportField>();
     _filters = new List<Filter>();
     _sel = new Select();
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:16,代码来源:Reports.cs

示例6: fixProfitAndLoss

 // TODO: Should be more like fixBalanceSheet, and use common totalling code
 IEnumerable<JObject> fixProfitAndLoss(IEnumerable<JObject> data)
 {
     _total = false;
     JObject last = null;
     string lastTotalBreak = null;
     string lastHeading = null;
     int sign = 1;
     Dictionary<string, decimal[]> totals = new Dictionary<string, decimal[]>();
     JObject spacer = new JObject().AddRange("@class", "totalSpacer");
     // Make list of fields to total
     foreach (ReportField f in _fields) {
         if (!f.Include) continue;
         string type = f.AsString("type");
         if (type != "decimal" && type != "double" && type != "credit" && type != "debit") continue;
         totals[f.Name] = new decimal[3];
     }
     // Function to add a total record (index is total level - 0=account type change, 1=Gross Profit, 2=Net Profit)
     Func<int, JObject> totalRecord = delegate(int index) {
         JObject t = new JObject().AddRange("@class", "total total" + index);
         foreach (string f in totals.Keys.ToList()) {
             t[f] = sign * totals[f][index];
             totals[f][index] = 0;
         }
         t["Heading"] = lastHeading;
         t[_sortOrder] = index == 0 ? "Total " + lastTotalBreak : lastTotalBreak;
         return t;
     };
     foreach (JObject r in data) {
         JObject record = new JObject(r);
         string totalBreak = record.AsString(_sortOrder);
         string heading = record.AsString("Heading");
         if (totalBreak != lastTotalBreak) {
             if (last != null) {
                 if (lastTotalBreak != null) {
                     // Total and spacer for account type change
                     yield return totalRecord(0);
                     yield return spacer;
                     if (lastHeading != heading) {
                         // Total and spacer for gross profit
                         lastTotalBreak = lastHeading;
                         sign = -1;
                         yield return totalRecord(1);
                         yield return spacer;
                     }
                 }
             }
             lastTotalBreak = totalBreak;
             lastHeading = heading;
             // New account type heading
             yield return new JObject().AddRange("@class", "title", "Heading", heading, "AcctType", totalBreak);
         }
         sign = record.AsBool("Negate") ? -1 : 1;
         // Accumulate totals
         foreach (string f in totals.Keys.ToList()) {
             decimal v = record.AsDecimal(f);
             decimal[] tots = totals[f];
             for (int i = 0; i < tots.Length; i++) {
                 tots[i] += v;
             }
             record[f] = sign * v;
         }
         last = r;
         yield return record;
     }
     if (last != null) {
         // Total and spacer for last account type change
         yield return totalRecord(0);
         yield return spacer;
         // Total and spacer for gross profit
         lastTotalBreak = lastHeading;
         sign = -1;
         yield return totalRecord(2);
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:75,代码来源:Reports.cs

示例7: importCategories

 /// <summary>
 /// Import series of categories (accounts, in our system)
 /// </summary>
 void importCategories()
 {
     status("Importing Categories");
     JObject o = new JObject();
     while (getLine()) {
         switch (_tag) {
             case "!":
                 return;
             case "^":		// End of record
                 if(!string.IsNullOrEmpty(o.AsString("AccountName")))
                     _account = (int)_module.Database.ForeignKey("Account", o);
                 o = new JObject();
                 break;
             case "N":
                 o["AccountName"] = _accountName = _value;
                 break;
             case "D":
                 o["AccountDescription"] = _value;
                 break;
             case "E":
                 o["AccountTypeId"] = (int)AcctType.Expense;
                 break;
             case "I":
                 o["AccountTypeId"] = (int)AcctType.Income;
                 break;
             case "B":
                 break;
             default:
                 throw new CheckException("Unexpected input:{0}", _line);
         }
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:35,代码来源:QifImporter.cs

示例8: Value

 public override JToken Value(Database db, JObject data)
 {
     string nameType;
     switch (data.AsString("Account")) {
         case "Purchase Ledger":
             nameType = "S";
             break;
         case "Sales Ledger":
             nameType = "C";
             break;
         default:
             string type = data.AsString("Type");
             switch (type) {
                 case "Invoice":
                 case "Payment":
                 case "Credit Memo":
                     nameType = "C";
                     break;
                 case "Bill":
                 case "Bill Pmt":
                 case "Credit":
                     nameType = "S";
                     break;
                 default:
                     nameType = type.IndexOf("Bill Pmt") == 0 ? "S" : "O";
                     break;
             }
             break;
     }
     JObject keyData = new JObject().AddRange("Type", nameType, "Name", base.Value(db, data));
     return db.ForeignKey("NameAddress", keyData);
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:32,代码来源:Importer.cs

示例9: importSecurity

 void importSecurity()
 {
     status("Importing Security");
     JObject o = new JObject();
     o["PriceDate"] = new DateTime(1900, 1, 1);
     while (getLine()) {
         switch (_tag) {
             case "!":
                 return;
             case "^":	// End of record
                 if(!string.IsNullOrWhiteSpace(o.AsString("SecurityName")) && !string.IsNullOrWhiteSpace(o.AsString("Ticker")))
                     _module.Database.ForeignKey("Security", o);
                 getLine();	// Get next line for caller to process
                 return;
             case "N":
                 o["SecurityName"] = _value;
                 break;
             case "S":	// Security stock ticker
                 o["Ticker"] = _value;
                 break;
             case "T":	// Type? (Stock)
                 break;
             default:
                 throw new CheckException("Unexpected input:{0}", _line);
         }
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:27,代码来源:QifImporter.cs

示例10: reportJson

 /// <summary>
 /// Produce report output from original request, list of records, and list of potentially duplicate tables 
 /// (i.e. parent tables of main record, which you want to look like headings)
 /// </summary>
 /// <param name="json">Original request</param>
 /// <param name="report">Records</param>
 /// <param name="tables">Potentially duplicate tables</param>
 /// <returns>Json to send to javascript</returns>
 public JObject reportJson(JObject json, IEnumerable<JObject> report, params string [] tables)
 {
     // Use ReportName as right hand end of page title
     Title = Regex.Replace(Title, "-[^-]*$", "- " + json.AsString("ReportName"));
     if (_sortFields != null && _sortFields.Length > 0 && tables.Length > 0) {
         // SortField table is always potentially duplicated - i.e. all the data from the table for the first sort field
         // will repeat until sort field changes
         ReportField sortField = fieldFor(_sortFields[0]);
         tables[0] = sortField.Table;
         // Move sort fields to front of field list
         int p = 0;
         foreach(string f in _sortFields)
             positionField(f, p++);
         if (_split) {
             // Split report shows sort field data on 1 line, and main data on next line
             ReportField fld = _fields.FirstOrDefault(f => f.Include && !tables.Contains(f.Table));
             if(fld != null)
                 fld["newRow"] = true;
         }
     }
     json["fields"] = _fields.Where(f => !f.Hidden).ToJToken();
     json["filters"] = getFilters().ToJToken();
     json["sorting"] = new JObject().AddRange(
                 "sort", _sortOrder,
                 "desc", _sortDescending,
                 "total", _total,
                 "split", _split);
     return new JObject().AddRange(
         "settings", json,
         "filters", new JArray(_filters),
         "sortOrders", _sortOrders,
         "report", removeRepeatsAndTotal(report, tables)
         );
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:42,代码来源:Reports.cs

示例11: fixBalanceSheet

 // TODO: Should use common totalling code
 IEnumerable<JObject> fixBalanceSheet(IEnumerable<JObject> data)
 {
     _total = false;
     JObject last = null;
     string lastTotalBreak = null;
     string lastHeading = null;
     int sign = 1;
     decimal retainedProfitCP = 0, retainedProfitPP = 0, retainedProfitOld = 0;
     Dictionary<string, decimal[]> totals = new Dictionary<string, decimal[]>();
     JObject spacer = new JObject().AddRange("@class", "totalSpacer");
     // Make list of fields to total
     foreach (ReportField f in _fields) {
         if (!f.Include) continue;
         string type = f.AsString("type");
         if (type != "decimal" && type != "double" && type != "credit" && type != "debit") continue;
         totals[f.Name] = new decimal[3];
     }
     // Function to add a total record (index is total level - 0=account type change, 1=heading change, 2=total assets/total liabilities & equity)
     Func<int, JObject> totalRecord = delegate(int index) {
         JObject t = new JObject().AddRange("@class", "total total" + index);
         foreach (string f in totals.Keys.ToList()) {
             t[f] = sign * totals[f][index];
             totals[f][index] = 0;
         }
         if (index == 0) {
             t["Heading"] = lastHeading;
             t[_sortOrder] = "Total " + lastTotalBreak;
         } else {
             t["Heading"] = "Total " + lastHeading;
         }
         return t;
     };
     if(data.FirstOrDefault(r => r.AsInt("idAccount") == (int)Acct.RetainedEarnings) == null) {
         // Need a retained earnings account line, so create one if missing
         data = data.Concat(Enumerable.Repeat(new JObject().AddRange(
                 "idAccount", (int)Acct.RetainedEarnings,
                 "Heading", "Equities",
                 "BalanceSheet", 1,
                 "AccountTypeId", (int)AcctType.Equity,
                 "AcctType", "Equity",
                 "AccountName", "Retained Earnings",
                 "Negate", 1,
                 "CurrentPeriod", 0M,
                 "PreviousPeriod", 0M,
                 "Old", 0M
         ), 1));
     }
     foreach (JObject r in data) {
         JObject record = new JObject(r);
         string totalBreak = record.AsString(_sortOrder);
         string heading = record.AsString("Heading");
         if (record.AsInt("BalanceSheet") == 0) {
             // Accumulate profit and loss postings
             retainedProfitCP += record.AsDecimal("CurrentPeriod");
             retainedProfitPP += record.AsDecimal("PreviousPeriod");
             retainedProfitOld += record.AsDecimal("Old");
             continue;
         } else {
             if (r.AsInt("idAccount") == (int)Acct.RetainedEarnings) {
                 // Add accumulated profit into retained earnings
                 record["PreviousPeriod"] = record.AsDecimal("PreviousPeriod") + retainedProfitOld;
                 record["CurrentPeriod"] = record.AsDecimal("CurrentPeriod") + retainedProfitPP;
                 record.Remove("idAccount");		// So user can't click on it to expand
             }
             // Balance sheet shows totals so far, so add in previous periods
             record["PreviousPeriod"] = record.AsDecimal("PreviousPeriod") + record.AsDecimal("Old");
             record["CurrentPeriod"] = record.AsDecimal("CurrentPeriod") + record.AsDecimal("PreviousPeriod");
             record.Remove("Old");
         }
         if (totalBreak != lastTotalBreak) {
             if (last != null) {
                 if (lastTotalBreak != null) {
                     // Add total and spacer for account type change
                     spacer["Heading"] = lastHeading;
                     yield return totalRecord(0);
                     yield return spacer;
                     if (lastHeading != heading) {
                         // Add total and spacer for heading change
                         lastTotalBreak = lastHeading;
                         yield return totalRecord(1);
                         spacer.Remove("Heading");
                         yield return spacer;
                         if (lastHeading.Contains("Assets") && !heading.Contains("Assets")) {
                             // Add total and spacer for total assets
                             lastHeading = "Assets";
                             sign = 1;
                             yield return totalRecord(2);
                             yield return spacer;
                         }
                     }
                 }
             }
             if (lastHeading != heading)	// Next heading if required
                 yield return new JObject().AddRange("@class", "title", "Heading", heading);
             lastTotalBreak = totalBreak;
             lastHeading = heading;		// Account type heading
             yield return new JObject().AddRange("@class", "title", "Heading", heading, "AcctType", totalBreak);
         }
         sign = record.AsBool("Negate") ? -1 : 1;
//.........这里部分代码省略.........
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:101,代码来源:Reports.cs

示例12: CreateRideStatus

        protected void CreateRideStatus(JObject o)
        {
            var attraction_id=RideId(o.AsString("ride_name"));
            var idToken = JToken.FromObject(attraction_id);
            o.Add("attraction_id", idToken);
            o.Remove("ride_name");

            CreateDoc("ride_status", o);
        }
开发者ID:richard-delorenzi,项目名称:couch-experiment-test,代码行数:9,代码来源:QcouchDb.cs

示例13: importAccount

 /// <summary>
 /// Import account info for a single bank/card/security account
 /// </summary>
 void importAccount()
 {
     status("Importing Account");
     JObject o = new JObject();
     while (getLine()) {
         switch (_tag) {
             case "!":
                 return;
             case "^":		// End of record
                 if(!string.IsNullOrEmpty(o.AsString("AccountName")))
                     _account = (int)_module.Database.ForeignKey("Account", o);
                 getLine();	// Get next line for caller to process
                 return;
             case "N":
                 o["AccountName"] = _accountName = _value;
                 break;
             case "D":
                 o["AccountDescription"] = _value;
                 break;
             case "S":	// Security stock ticker
                 break;
             case "T":
                 switch (_value) {
                     case "CCard":
                         o["AccountTypeId"] = (int)AcctType.CreditCard;
                         break;
                     case "Bank":
                         o["AccountTypeId"] = (int)AcctType.Bank;
                         break;
                     case "Stock":
                     case "Invst":
                         o["AccountTypeId"] = (int)AcctType.Investment;
                         break;
                     default:
                         throw new CheckException("Unexpected account type:{0}", _line);
                 }
                 break;
             default:
                 throw new CheckException("Unexpected input:{0}", _line);
         }
     }
 }
开发者ID:nikkilocke,项目名称:AccountServer,代码行数:45,代码来源:QifImporter.cs


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