private void PopulateTreeView(TreeNodeCollection c,JSONDictionary js) { foreach (KeyValuePair<string, object> kvp in js) { TreeNode n = new TreeNode(kvp.Key); if (kvp.Value is JSONDictionary) { PopulateTreeView(n.Nodes, kvp.Value as JSONDictionary); } else if (kvp.Value is ArrayList) { PopulateTreeView(n.Nodes, kvp.Value as ArrayList); } else { n.Text = n.Text + ": " + kvp.Value; } c.Add(n); } }
private void SaveData() { List <JSONDictionary> JSONDict = new List <JSONDictionary>(); foreach (Node currentNode in nodes) { JSONDictionary thisJSON = new JSONDictionary(); thisJSON.nodeID = currentNode.nodeID; thisJSON.name = currentNode.titleString; thisJSON.body = currentNode.bodyString; thisJSON.uniqueIDString = currentNode.uniqueIDString; thisJSON.blackboardString = currentNode.blackboardString; thisJSON.variableValue = currentNode.valueBool; thisJSON.variableString = currentNode.variableString; thisJSON.position = currentNode.rect; thisJSON.type = currentNode.type; thisJSON.option1 = currentNode.option1String; thisJSON.option2 = currentNode.option2String; thisJSON.option3 = currentNode.option3String; thisJSON.option4 = currentNode.option4String; JSONDict.Add(thisJSON); } List <JSONConnectionDictionary> JSONConnectDict = new List <JSONConnectionDictionary>(); if (connections.Count != 0) { foreach (Connection currentConnection in connections) { JSONConnectionDictionary thisJSON = new JSONConnectionDictionary(); thisJSON.inPointID = currentConnection.inPoint.node.nodeID; thisJSON.outPointID = currentConnection.outPoint.node.nodeID; thisJSON.outBoolType = currentConnection.outPoint.boolType; thisJSON.optionNumber = currentConnection.outPoint.optionNumber; JSONConnectDict.Add(thisJSON); } } JSONList JSONListO = new JSONList(); JSONListO.dataList = JSONDict; JSONListO.connectionList = JSONConnectDict; string dataAsJson = JsonUtility.ToJson(JSONListO); File.WriteAllText(filePath, dataAsJson); }
private void PopulateTreeView(TreeNodeCollection c, JSONDictionary js) { foreach (KeyValuePair <string, object> kvp in js) { TreeNode n = new TreeNode(kvp.Key); if (kvp.Value is JSONDictionary) { PopulateTreeView(n.Nodes, kvp.Value as JSONDictionary); } else if (kvp.Value is ArrayList) { PopulateTreeView(n.Nodes, kvp.Value as ArrayList); } else { n.Text = n.Text + ": " + kvp.Value; } c.Add(n); } }
public void ParseTest() { string jsonAsText = "[ true, \"Value2\", false, null ]"; object o = JSONReader.Parse(jsonAsText); Assert.IsTrue(o is ArrayList); ArrayList a = o as ArrayList; Assert.AreEqual(4, a.Count); Assert.AreEqual(false, a[2]); jsonAsText = "{ \"Name\" : true }"; o = JSONReader.Parse(jsonAsText); Assert.IsTrue(o is JSONDictionary); jsonAsText = "{ \"name\" : [ true, \"Value2\", false ], \"sub\" : { \"subname\" : 1234 } }"; o = JSONReader.Parse(jsonAsText); Assert.IsTrue(o is JSONDictionary); JSONDictionary j = o as JSONDictionary; a = j["name"] as ArrayList; Assert.IsNotNull(a); }