private void getChildValue(JToken j, DataTable dt) { JEnumerable <JToken> je = j.Children(); if (je.Count <JToken>() > 0) { foreach (JToken jt in je) { getChildValue(jt, dt); Console.WriteLine("HasChildren.I am " + jt.Path); } } else { //retList.Add(j.Path +":" + j.CreateReader().ReadAsString()); Regex reg = new Regex("\\[[0-9]*\\]"); String columnName = reg.Replace(j.Path, ""); if (!dt.Columns.Contains(columnName)) { dt.Columns.Add(j.Path); } DataRow dr = dt.NewRow(); dr[columnName] = j.CreateReader().ReadAsString(); } }
public static void cancelOpenOrders(string accessKey, string secretKey, string tonce) { string paramQueryString = "tonce=" + tonce + "&accesskey=" + accessKey + "&requestmethod=post&id=1&method=getOrders¶ms="; string hash_hmac = getHMACSHA1Hash(accessKey, secretKey, paramQueryString); string str = sendPostByWebRequest(hash_hmac, tonce, "{\"method\": \"getOrders\", \"params\": [], \"id\": 1}"); JObject o = JObject.Parse(str); JEnumerable <JToken> orders = o["result"]["order"].Children(); while (orders.Count() > 0) { foreach (var item in orders) { } } Console.WriteLine(orders.Count()); }
// private void Initialize(string path) { string josnString = File.ReadAllText(path, Encoding.Default); jo = JObject.Parse(josnString); string name = jo.First.First.Path; JToken ltest = jo.First.First.First; JEnumerable <JToken> ll = ltest.Children(); foreach (JToken grandGrandChild in ltest) { var property = grandGrandChild as JProperty; if (property != null) { string mmm = property.Name; RowHead.Add(mmm); // MessageBox.Show(property.Name + ":" + property.Value); } } int m = ll.Count(); for (int i = 0; i < m; i++) { } lengthRow = jo[name].Count(); lengthCol = jo[name][0].Count(); int row = lengthRow; // 行数 int col = lengthCol; // 列数 for (int i = 0; i < col; i++) { TableCell cell = new TableCell(); string cellValue = RowHead[i].ToString(); cell.Text = cellValue; tableHeaderName.Cells.AddAt(i, cell); } for (int i = 0; i < row; i++) { TableRow tr = new TableRow(); ExperimentDataTable.Rows.Add(tr); for (int j = 0; j < col; j++) { TableCell cell = new TableCell(); string cellValue = jo[name][i][RowHead[j]].ToString(); cell.Text = cellValue; tr.Cells.AddAt(j, cell); } } }
private static Difference CompareItems(JArray actual, JArray expected, JPath path) { JEnumerable <JToken> actualChildren = actual.Children(); JEnumerable <JToken> expectedChildren = expected.Children(); if (actualChildren.Count() != expectedChildren.Count()) { return(new Difference(DifferenceKind.DifferentLength, path)); } for (int i = 0; i < actualChildren.Count(); i++) { Difference firstDifference = FindFirstDifference(actualChildren.ElementAt(i), expectedChildren.ElementAt(i), path.AddIndex(i)); if (firstDifference != null) { return(firstDifference); } } return(null); }
public static JEnumerable <JToken> FindFieldsJEnumerable(string fieldname, string payload, IEnumerable <string> filterPermutations) { try { JEnumerable <JToken> returnObj = new JEnumerable <JToken>(); // read by categories JObject rss = JObject.Parse(payload); string wildcardPath = string.Empty; foreach (var ea in filterPermutations) { wildcardPath = ea + fieldname; var _sTokens = rss.SelectTokens(wildcardPath); if (_sTokens.ToList().Count > 0) { bool exists = false; //write the found to a list foreach (var _jtkn in _sTokens) { foreach (var jtoken in returnObj) { if (_jtkn == jtoken) { //DO SOMETHING exists = true; break; } } if (exists == false) { returnObj.Append(_jtkn); } } } } var a = returnObj.Count(); return(returnObj); } catch (Exception ex) { throw ex; } }
public void EmptyJEnumerableCount() { JEnumerable<JToken> tokens = new JEnumerable<JToken>(); Assert.AreEqual(0, tokens.Count()); }
public void EmptyJEnumerableCount() { JEnumerable <JToken> tokens = new JEnumerable <JToken>(); Assert.AreEqual(0, tokens.Count()); }
public override bool Execute() { string inputFile = InputDepsFilePath.ItemSpec; string outputFile = OutputDepsFilePath.ItemSpec; string[] keptAssemblies = KeptAssemblies.Select(a => a.ItemSpec).ToArray(); string[] allAssemblies = ManagedPublishAssemblies.Select(a => a.ItemSpec).ToArray(); string[] removedAssemblies = allAssemblies.Except(keptAssemblies).ToArray(); var removedAssembliesSet = new HashSet <string> (removedAssemblies, StringComparer.InvariantCultureIgnoreCase); JObject o = JObject.Parse(File.ReadAllText(inputFile)); JObject targets = (JObject)o["targets"]; // Remove targets foreach (JProperty target in targets.Children()) { JEnumerable <JToken> children = target.Value.Children(); for (int i = 0; i < children.Count(); ++i) { //foreach (JProperty subtarget in target.Value.Children()) { var subtarget = (JProperty)children.ElementAt(i); string name = subtarget.Name.Substring(0, subtarget.Name.IndexOf('/')); if (removedAssembliesSet.Contains(name + ".dll")) { subtarget.Remove(); i--; continue; } // Remove dependencies var dependencies = subtarget.Value["dependencies"]; if (dependencies != null) { for (int j = 0; j < dependencies.Count(); ++j) { var dependency = ((JProperty)dependencies.ElementAt(j)); if (removedAssembliesSet.Contains(dependency.Name + ".dll")) { dependency.Remove(); j--; continue; } } } // Remove runtimes var runtimes = subtarget.Value["runtime"]; if (runtimes != null) { for (int j = 0; j < runtimes.Count(); ++j) { var runtime = ((JProperty)runtimes.ElementAt(j)); string runtimeFileName = runtime.Name.Substring(runtime.Name.LastIndexOf('/') + 1); if (removedAssembliesSet.Contains(runtimeFileName)) { runtime.Remove(); j--; continue; } } } } } // Remove libraries JObject libraries = (JObject)o["libraries"]; JEnumerable <JToken> libraryChildren = libraries.Children(); for (int i = 0; i < libraryChildren.Count(); ++i) { var library = (JProperty)libraryChildren.ElementAt(i); string name = library.Name.Substring(0, library.Name.IndexOf('/')); if (removedAssembliesSet.Contains(name + ".dll")) { library.Remove(); i--; continue; } } File.WriteAllText(outputFile, o.ToString()); return(true); }