private static JProperty DiffUnsafeOptions(JsonNode unsafeOptionsNode, JsonNode otherUnsafeOptionsNode) { Contract.Requires(unsafeOptionsNode != null); Contract.Requires(otherUnsafeOptionsNode != null); Contract.Requires(unsafeOptionsNode.Name == otherUnsafeOptionsNode.Name); // Get the diff result of the single values in unsafeUnsafeOptions JObject result = DiffNameValuePairs(unsafeOptionsNode, otherUnsafeOptionsNode); // Deal with the preserveOutputInfo struct in unsafeUnsafeOptions JsonNode preserveOutputInfoNode = JsonTree.FindNodeByName(unsafeOptionsNode, nameof(PreserveOutputsInfo)); JsonNode otherpreserveOutputInfoNode = JsonTree.FindNodeByName(otherUnsafeOptionsNode, nameof(PreserveOutputsInfo)); if (preserveOutputInfoNode != null || otherpreserveOutputInfoNode != null) { JObject preserveOutputInfoResult = DiffNameValuePairs( preserveOutputInfoNode ?? new JsonNode() { Name = nameof(PreserveOutputsInfo) }, otherpreserveOutputInfoNode ?? new JsonNode() { Name = nameof(PreserveOutputsInfo) }); if (preserveOutputInfoResult != null) { result = result ?? new JObject(); AddPropertyIfNotNull(result, new JProperty(nameof(PreserveOutputsInfo), preserveOutputInfoResult)); } } return(result != null ? new JProperty(unsafeOptionsNode.Name, result) : null); }
public ActionResult GetTree() { int id = int.Parse(Request["id"]); JsonTree jsontree = easyuibll.GetModel(id); return(Json(jsontree, JsonRequestBehavior.AllowGet)); }
public void ThatArraysCanHaveArrays() { var parser = Utilities.jsonParserFromString("[123,[],[654,888],345]"); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(4, root.Length); Assert.AreEqual(123d, root[0]); Assert.AreEqual(345d, root[3]); var a1 = root[1]; var a2 = root[2]; Assert.AreEqual(typeof(object[]), a1.GetType()); Assert.AreEqual(typeof(object[]), a2.GetType()); Assert.AreEqual(0, ((object[])a1).Length); Assert.AreEqual(2, ((object[])a2).Length); var o2 = (object[])a2; Assert.AreEqual(654d, o2[0]); Assert.AreEqual(888d, o2[1]); }
public void ThatArraysCanHaveArrays() { var parser = Utilities.jsonParserFromString("[123,[],[654,888],345]"); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(4, root.Length); Assert.AreEqual(123d, root[0]); Assert.AreEqual(345d, root[3]); var a1 = root[1]; var a2 = root[2]; Assert.AreEqual(typeof(object[]), a1.GetType()); Assert.AreEqual(typeof(object[]), a2.GetType()); Assert.AreEqual(0, ((object[])a1).Length); Assert.AreEqual(2, ((object[])a2).Length); var o2 = (object[])a2; Assert.AreEqual(654d, o2[0]); Assert.AreEqual(888d, o2[1]); }
void Json2TreeNode(string srcFilePath) { string jsonData = null; bool isCorrectFormat = false;//CheckJsonFile(srcFilePath, out jsonData); jsonData = ReadFile(srcFilePath, out isCorrectFormat); if (isCorrectFormat) { string srcFileName = Path.GetFileName(srcFilePath).Split('.')[0]; string jsonFinal = @jsonData; ConfigTree.Nodes.Clear(); TreeNode root = new TreeNode(); string errStr = null; JsonTree.BindTreeView(ref root, jsonFinal, out errStr); for (int i = 0; i < root.GetNodeCount(false); i++) { this.ConfigTree.Nodes.Add(root.Nodes[i]); } if (!string.IsNullOrEmpty(errStr)) { LogError(errStr); } else { Log("格式化成功"); CollapseCheckBox.Checked = true; } } else { LogError("请检查Json格式,确保没有 “test”:{} 等空对象结构 "); } }
/// <summary> /// Get strong fingerprint tree for the entry /// </summary> public JsonNode GetStrongFingerprintTree() { var strongEntry = m_entry.StrongFingerprintEntry; var strongFingerprintTree = JsonTree.Deserialize(strongEntry.StrongFingerprintToInputs.Value); var pathSetTree = JsonTree.Deserialize(strongEntry.PathSetHashToInputs.Value); return(MergeStrongFingerprintAndPathSetTrees(strongFingerprintTree, pathSetTree)); }
/// <summary> /// Diffs strong fingerprints. /// </summary> /// <param name="pathSetHash">Pathset hash.</param> /// <param name="pathSetTree">Pathset tree.</param> /// <param name="strongFingerprintInputTree">Strong fingerprint input tree.</param> /// <param name="otherPathSetHash">Other pathset hash.</param> /// <param name="otherPathSetTree">Other pathset tree.</param> /// <param name="otherStrongFingerprintInputTree">Other strong fingerprint input tree.</param> /// <param name="getDirectoryMembership">Delegate for getting directory membership.</param> /// <param name="getOtherDirectoryMembership">Delegate for getting other directory membership.</param> /// <returns></returns> public static JObject DiffPathSets( string pathSetHash, JsonNode pathSetTree, JsonNode strongFingerprintInputTree, string otherPathSetHash, JsonNode otherPathSetTree, JsonNode otherStrongFingerprintInputTree, Func <string, IReadOnlyList <string> > getDirectoryMembership, Func <string, IReadOnlyList <string> > getOtherDirectoryMembership) { JObject result = new JObject(); if (pathSetHash == otherPathSetHash) { return(result); } // { // PathSetHash: { Old: old_path_set_hash, New: new_path_set_hash } // } AddPropertyIfNotNull(result, RenderSingleValueDiff("PathSetHash", pathSetHash, otherPathSetHash)); JsonNode unsafeOptionsNode = JsonTree.FindNodeByName(pathSetTree, ObservedPathSet.Labels.UnsafeOptions); JsonNode otherUnsafeOptionsNode = JsonTree.FindNodeByName(otherPathSetTree, ObservedPathSet.Labels.UnsafeOptions); // This is less ideal because we can't see the difference. // TODO: dump unsafe option data to the fingerprint store so that we can analyze the content. // { // UnsafeOptions: { Old: old_bits, New: new_bits: } // } AddPropertyIfNotNull(result, RenderSingleValueDiff(ObservedPathSet.Labels.UnsafeOptions, unsafeOptionsNode.Values[0], otherUnsafeOptionsNode.Values[0])); AddPropertyIfNotNull( result, DiffObservedPaths( pathSetTree, strongFingerprintInputTree, otherPathSetTree, otherStrongFingerprintInputTree, getDirectoryMembership, getOtherDirectoryMembership)); JsonNode obsFileNameNode = JsonTree.FindNodeByName(pathSetTree, ObservedPathSet.Labels.ObservedAccessedFileNames); JsonNode otherObsFileNameNode = JsonTree.FindNodeByName(otherPathSetTree, ObservedPathSet.Labels.ObservedAccessedFileNames); bool hasDiff = ExtractUnorderedListDiff(obsFileNameNode.Values, otherObsFileNameNode.Values, out var addedFileNames, out var removedFileName); if (hasDiff) { result.Add(new JProperty( ObservedPathSet.Labels.ObservedAccessedFileNames, RenderUnorderedListDiff(addedFileNames, removedFileName, RenderPath))); } Contract.Assert(result.Count > 0); return(result); }
public void RepeatNameTest() { string jsonA = "{\"Object\":[{\"PathSet\":\"VSO0:890000000000000000000000000000000000000000000000000000000000000000\"}," + "{\"ObservedInputs\":[{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"A\":\"\"},{\"P\":\"\"},{\"E\":\"VSO0:4D939FB1E1CE7586909F84F4FEFB0F385B31DD586FF97FC14874BCDB4B2A801400\"}]}]}"; var treeA = JsonTree.Deserialize(jsonA); string deserialized = JsonTree.Serialize(treeA); XAssert.AreEqual(JsonTree.PrettyPrintJson(jsonA), deserialized); }
private static IReadOnlyList <string> GetDirectoryMembership(FingerprintStore store, string directoryFingerprint) { if (!store.TryGetContentHashValue(directoryFingerprint, out string storedValue)) { return(null); } var directoryMembershipTree = JsonTree.Deserialize(storedValue); return(directoryMembershipTree.Children.First.Value.Values); }
private void LoadEntity(DataRow row, JsonTree jsontree) { Dictionary <string, string> test = new Dictionary <string, string>(); jsontree.id = Convert.ToInt32(row["ID"]); jsontree.text = row["CityName"] != DBNull.Value ? row["CityName"].ToString() : string.Empty; //jsontree.score = Convert.ToInt32(row["Score"]); jsontree.score = row["Score"] != DBNull.Value ? Convert.ToInt32(row["Score"]) : 0; jsontree.state = "open"; jsontree.attributes = test; jsontree.children = "null"; }
public void ThatArraysCanBeEmpty() { var str = "[]"; var parser = Utilities.jsonParserFromString(str); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(0, root.Length); }
public void ThatEmptyObjectParses() { var parser = Utilities.jsonParserFromString("{}"); var tree = parser.@object().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.@object(); Assert.AreEqual(typeof(KeyValuePair <string, object>[]), root.GetType()); Assert.AreEqual(0, root.Length); }
private static void PopulateNameValuePairData(JsonNode nameValuePairNode, Dictionary <string, NameValuePairData> nameValuePairData) { JsonTree.VisitTree( nameValuePairNode, node => { nameValuePairData[node.Name] = new NameValuePairData( node.Name, node.Values.Count > 0 ? node.Values[0] : CacheMissAnalysisUtilities.RepeatedStrings.MissingValue); }, recurse: false); }
public void ThatArraysCanBeEmpty() { var str = "[]"; var parser = Utilities.jsonParserFromString(str); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(0, root.Length); }
public void ThatEmptyObjectParses() { var parser = Utilities.jsonParserFromString("{}"); var tree = parser.@object().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.@object(); Assert.AreEqual(typeof(KeyValuePair<string, object>[]), root.GetType()); Assert.AreEqual(0, root.Length); }
public void ThatSingleAssignmentWorks() { var parser = Utilities.jsonParserFromString("\"key\":[1,2,3]"); var tree = parser.pair().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.kvp(); Assert.AreEqual("key", root.Key); Assert.AreEqual(typeof(object[]), root.Value.GetType()); Assert.AreEqual(2d, ((object[])root.Value)[1]); }
private Dictionary <string, string> CreateUrl(DataTable dt, JsonTree jt) //把Url属性添加到attribute中,如果需要别的属性,也可以在这里添加 { Dictionary <string, string> dic = new Dictionary <string, string>(); int keyid = jt.id; DataRow[] urlList = dt.Select("id='" + keyid + "'"); string url = urlList[0]["Url"].ToString(); string score = urlList[0]["Score"].ToString(); dic.Add("url", url); dic.Add("score", score); return(dic); }
public void BasicTest() { string jsonA = "{\"Object\":[{\"WeakFingerprint\":\"097ED1ED5703816B8F286410076E658260D029BC\"},{\"StrongFingerprint\":\"C926945B5824E1CC7C512D66FB3B8FE869B71936\"}]}"; string jsonB = "{\"Object\":[{\"WeakFingerprint\":\"097ED1ED5703816B8F286410076E658260D029BC\"},{\"StrongFingerprint\":\"DefinitelyNotTheSameFingerprint\"}]}"; var treeA = JsonTree.BuildTree(jsonA); var treeB = JsonTree.BuildTree(jsonB); var changeList = JsonTree.DiffTrees(treeA, treeB); AssertUnchanged("WeakFingerprint", changeList); AssertChanged("StrongFingerprint", changeList); }
public AdxTableSchema GenerateTableSchema(string name, string json) { // Get leaf nodes from the JSON. The leaf nodes contain the // necessary information to generate the ADX table schema. var jsonTree = new JsonTree(json); var leafNodes = jsonTree.GetLeafNodes(); // generate the ADX column definitions from the leaf nodes. var adxColumnSchemas = _columnSchemaFactory.GenerateColumnSchemas(leafNodes); return(new AdxTableSchema(name, adxColumnSchemas)); }
public void ThatArraysHasNumbers() { var parser = Utilities.jsonParserFromString("[123,234,345]"); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(123d, root[0]); Assert.AreEqual(234d, root[1]); Assert.AreEqual(345d, root[2]); }
public void ThatSingleAssignmentWorks() { var parser = Utilities.jsonParserFromString("\"key\":[1,2,3]"); var tree = parser.pair().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.kvp(); Assert.AreEqual("key", root.Key); Assert.AreEqual(typeof(object[]), root.Value.GetType()); Assert.AreEqual(2d, ((object[])root.Value)[1]); }
private void buildJsonTree(string curdir, JsonTree treenode, string replacestr) { string[] dirs = Directory.GetDirectories(curdir); foreach (string dir in dirs) { JsonTree tree = new JsonTree() { id = Server.UrlEncode(dir.Replace(replacestr, "")), text = System.IO.Path.GetFileName(dir) }; treenode.children.Add(tree); buildJsonTree(dir, tree, replacestr); } }
private static JsonObject ParseANTLRStream(ANTLRStringStream inputStream) { var lexer = new JsonLexer(inputStream); var tokens = new CommonTokenStream(lexer); var parser = new JsonParser(tokens); var parseTree = parser.@object().Tree; var stream = new CommonTreeNodeStream(parseTree); var tree = new JsonTree(stream); var @object = tree.@object(); Contract.Assume(@object != null); return(new JsonObject(JsonValueTypes.Interpret(@object))); }
public void ThatArraysCanHaveStrings() { var str = "[\"oeu\",\"uu\"]"; var parser = Utilities.jsonParserFromString(str); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(2, root.Length); Assert.AreEqual("oeu", root[0]); Assert.AreEqual("uu", root[1]); }
public void ThatArraysHasNumbers() { var parser = Utilities.jsonParserFromString("[123,234,345]"); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(123d, root[0]); Assert.AreEqual(234d, root[1]); Assert.AreEqual(345d, root[2]); }
public void ThatArraysCanHaveStrings() { var str = "[\"oeu\",\"uu\"]"; var parser = Utilities.jsonParserFromString(str); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(2, root.Length); Assert.AreEqual("oeu", root[0]); Assert.AreEqual("uu", root[1]); }
public override int Analyze() { using (var pipSession = m_storeReader.StartPipRecordingSession(PipFormattedSemistableHash)) { m_writer.WriteLine("WEAKFINGERPRINT:"); m_writer.WriteLine(JsonTree.PrintTree(pipSession.GetWeakFingerprintTree())); m_writer.WriteLine(); m_writer.WriteLine("STRONGFINGERPRINT:"); m_writer.WriteLine(JsonTree.PrintTree(pipSession.GetStrongFingerprintTree())); } m_writer.Flush(); return(0); }
public void NestedNamelessArraysTest() { var jsonA = "{\"key\":[\"value\", [\"nestedValue\"]]}"; var treeA = JsonTree.Deserialize(jsonA); var keyNode = JsonTree.FindNodeByName(treeA, "key"); XAssert.IsTrue(keyNode.Values.Contains("value") && keyNode.Values.Contains("nestedValue")); string deserialized = JsonTree.Serialize(treeA); XAssert.IsTrue(deserialized.Contains("value") && deserialized.Contains("nestedValue")); XAssert.AreNotEqual(JsonTree.PrettyPrintJson(jsonA), deserialized); }
public int Update(JsonTree jsontree) { string sql = "update Tree set CityName=@text,Score=@score where id=@id"; SqlParameter[] pars = { new SqlParameter("@text", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@score", SqlDbType.Int) }; pars[0].Value = jsontree.text; pars[1].Value = jsontree.id; pars[2].Value = jsontree.score; return(SqlHelper.ExecuteNonquery(sql, CommandType.Text, pars)); }
public void ObjectWithSimplePair() { var parser = Utilities.jsonParserFromString("{\"testKey\":123.123}"); var tree = parser.@object().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.@object(); Assert.AreEqual(typeof(KeyValuePair <string, object>[]), root.GetType()); Assert.AreEqual(1, root.Length); Assert.AreEqual("testKey", root[0].Key); Assert.AreEqual(123.123, root[0].Value); }
public int Add(JsonTree jsontree) { string sql = "insert into Tree(CityName,ParentID,Score)VALUES (@text,@id,@score)"; SqlParameter[] pars = { new SqlParameter("@text", SqlDbType.NVarChar, 50), new SqlParameter("@id", SqlDbType.Int), new SqlParameter("@score", SqlDbType.Int) }; pars[0].Value = jsontree.text; pars[1].Value = jsontree.id; pars[2].Value = jsontree.score; return(SqlHelper.ExecuteNonquery(sql, CommandType.Text, pars)); }
private static BraceMatchingResult?GetMatchingBraces(JsonTree tree, int position) { var virtualChar = tree.Text.Find(position); if (virtualChar == null) { return(null); } var ch = virtualChar.Value; return(ch.Value is '{' or '[' or '(' or '}' or ']' or ')' ? FindBraceHighlights(tree, ch) : null); }
public static JsonArray Parse(string s) { var inputStream = new ANTLRStringStream(s); var lexer = new JsonLexer(inputStream); var tokens = new CommonTokenStream(lexer); var parser = new JsonParser(tokens); var parseTree = parser.array().Tree; var stream = new CommonTreeNodeStream(parseTree); var tree = new JsonTree(stream); var @object = tree.array(); Contract.Assume(@object != null); return(new JsonArray(JsonValueTypes.Interpret(@object))); }
public void RepeatNameTest() { string jsonA = "{\"Object\":[{\"PathSet\":\"VSO0:890000000000000000000000000000000000000000000000000000000000000000\"}," + "{\"ObservedInputs\":[{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"A\":\"\"},{\"P\":\"\"},{\"E\":\"VSO0:4D939FB1E1CE7586909F84F4FEFB0F385B31DD586FF97FC14874BCDB4B2A801400\"}]}]}"; string jsonB = "{\"Object\":[{\"PathSet\":\"VSO0:890000000000000000000000000000000000000000000000000000000000000000\"}," + "{\"ObservedInputs\":[{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"CHANGEDVALUE\"},{\"P\":\"\"},{\"P\":\"\"},{\"P\":\"\"},{\"E\":\"VSO0:4D939FB1E1CE7586909F84F4FEFB0F385B31DD586FF97FC14874BCDB4B2A801400\"}]}]}"; var treeA = JsonTree.BuildTree(jsonA); var treeB = JsonTree.BuildTree(jsonB); var changeList = JsonTree.DiffTrees(treeA, treeB); AssertChanged("P", changeList); AssertAdded("P", changeList); AssertRemoved("A", changeList); }
/// <summary> /// 公司选择树 /// </summary> /// <param name="ds">集合</param> /// <returns></returns> public List <JsonTree> GetTreeByShoper(DataSet ds) { List <JsonTree> list = new List <JsonTree>(); for (int b = 0; b < ds.Tables[0].Rows.Count; b++) { JsonTree model = new JsonTree(); model.id = ds.Tables[0].Rows[b]["Id"].ToString(); model.text = ds.Tables[0].Rows[b]["Name"].ToString(); model.leaf = true; model.expanded = true; list.Add(model); } return(list); }
public void BasicTest() { string jsonA = "{\"Dependencies\":[{\"a\":\"valueA\"},{\"b\":\"valueB\"}]}"; var treeA = JsonTree.Deserialize(jsonA); string deserialized = JsonTree.Serialize(treeA); XAssert.AreEqual(JsonTree.PrettyPrintJson(jsonA), deserialized); string jsonB = "{\"Object\":[{\"WeakFingerprint\":\"097ED1ED5703816B8F286410076E658260D029BC\"},{\"StrongFingerprint\":\"C926945B5824E1CC7C512D66FB3B8FE869B71936\"}]}"; var treeB = JsonTree.Deserialize(jsonB); string deserializedB = JsonTree.Serialize(treeB); XAssert.AreEqual(JsonTree.PrettyPrintJson(jsonB), deserializedB); }
public static JsonArray Parse(string s) { var inputStream = new ANTLRStringStream(s); var lexer = new JsonLexer(inputStream); var tokens = new CommonTokenStream(lexer); var parser = new JsonParser(tokens); var parseTree = parser.array().Tree; var stream = new CommonTreeNodeStream(parseTree); var tree = new JsonTree(stream); var @object = tree.array(); Contract.Assume(@object != null); return new JsonArray(JsonValueTypes.Interpret(@object)); }
public void ThatArraysCanHaveBooleansAndNull() { var parser = Utilities.jsonParserFromString("[true,true,false,true,false,null]"); var tree = parser.array().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.array(); Assert.AreEqual(6, root.Length); Assert.IsTrue((bool)root[0]); Assert.IsTrue((bool)root[1]); Assert.IsTrue((bool)root[3]); Assert.IsFalse((bool)root[2]); Assert.IsFalse((bool)root[4]); Assert.IsNull(root[5]); }
private void DrawJsonDataValueCollapsed(JsonTree jsonTree) { GUILayout.BeginHorizontal(); GUILayout.TextField(jsonTree.ToString(), "Label"); GUILayout.EndHorizontal(); }
private void DrawJsonDataValueExpanded(JsonTree jsonTree) { if (jsonTree.IsObject) { GUILayout.BeginVertical(); GUILayout.Label("{"); foreach (var prop in jsonTree.AsObject) { GUILayout.BeginHorizontal(); GUILayout.Space(JsonIndentSize); GUILayout.Label(prop.Name); GUILayout.Label(":"); DrawJsonDataValueExpanded(prop.Value); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.Label("}"); GUILayout.EndVertical(); } else if (jsonTree.IsArray) { GUILayout.BeginVertical(); GUILayout.Label("["); foreach (var item in jsonTree.AsArray) { GUILayout.BeginHorizontal(); GUILayout.Space(JsonIndentSize); DrawJsonDataValueExpanded(item); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } GUILayout.Label("]"); GUILayout.EndVertical(); } else { GUILayout.BeginHorizontal(); GUILayout.TextField(jsonTree.ToString(), "Label"); GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); } }
public void ObjectWithObjectAndArrayValues() { //var parser = Utilities.jsonParserFromString("{\"testKey\":[123],\"key2\":{},\"key3\":{\"key4\":234}}"); var parser = Utilities.jsonParserFromString("{\"testKey\":[123],\"key2\":{}}"); var tree = parser.toplevel().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.@object(); Assert.AreEqual(typeof(KeyValuePair<string, object>[]), root.GetType()); Assert.AreEqual(2, root.Length); Assert.AreEqual("testKey", root[0].Key); Assert.IsTrue(new object[] { 123d }.All(o => (root[0].Value as object[]).Contains(o))); Assert.AreEqual("key2", root[1].Key); Assert.AreEqual(typeof(KeyValuePair<string, object>[]), root[1].Value.GetType()); Assert.AreEqual(0, (root[1].Value as KeyValuePair<string, object>[]).Length); }
public void ThatWhiteSpaceIsIgnored() { var parser = Utilities.jsonParserFromString(" \n{\"testKey\"\n:[123],\t \"key2\" : {}\n\n\n} "); var tree = parser.toplevel().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.@object(); Assert.AreEqual(typeof(KeyValuePair<string, object>[]), root.GetType()); Assert.AreEqual(2, root.Length); Assert.AreEqual("testKey", root[0].Key); Assert.IsTrue(new object[] { 123d }.All(o => (root[0].Value as object[]).Contains(o))); Assert.AreEqual("key2", root[1].Key); Assert.AreEqual(typeof(KeyValuePair<string, object>[]), root[1].Value.GetType()); Assert.AreEqual(0, (root[1].Value as KeyValuePair<string, object>[]).Length); }
private static JsonObject ParseANTLRStream(ANTLRStringStream inputStream) { var lexer = new JsonLexer(inputStream); var tokens = new CommonTokenStream(lexer); var parser = new JsonParser(tokens); var parseTree = parser.@object().Tree; var stream = new CommonTreeNodeStream(parseTree); var tree = new JsonTree(stream); var @object = tree.@object(); Contract.Assume(@object != null); return new JsonObject(JsonValueTypes.Interpret(@object)); }
public void ObjectWithSimplePair() { var parser = Utilities.jsonParserFromString("{\"testKey\":123.123}"); var tree = parser.@object().Tree; var stream = new CommonTreeNodeStream(tree); var walker = new JsonTree(stream); var root = walker.@object(); Assert.AreEqual(typeof(KeyValuePair<string, object>[]), root.GetType()); Assert.AreEqual(1, root.Length); Assert.AreEqual("testKey", root[0].Key); Assert.AreEqual(123.123, root[0].Value); }