private object getJSONNodeValue(JSONNode node)
        {
            int intNode = 0;
              if (int.TryParse(node.Value, out intNode)) {
            return intNode;
              }

              float floatNode = 0.0f;
              if (float.TryParse(node.Value, out floatNode)) {
            return floatNode;
              }

              double doubleNode = 0.0;
              if (double.TryParse(node.Value, out doubleNode)) {
            return doubleNode;
              }

              bool boolNode = false;
              if (bool.TryParse(node.Value, out boolNode)) {
            return boolNode;
              }

              if (node.GetType() == typeof(JSONArray)) {
            IList<object> nodeList = new List<object>();
            foreach (JSONNode nodeInArray in node.AsArray) {
              nodeList.Add(this.getJSONNodeValue(nodeInArray));
            }
            return nodeList;
              }

              if (node.GetType() == typeof(JSONClass)) {
            IDictionary<string, object> nodeDictionary = new Dictionary<string, object>();
            foreach (KeyValuePair<string, JSONNode> kvp in node.AsObject) {
              nodeDictionary.Add(kvp.Key, this.getJSONNodeValue(kvp.Value));
            }
            return nodeDictionary;
              }

              // if the Node isn't one type of int/float/double/bool/list/dictionary, then we should save it as a string
              return node.ToString();
        }
예제 #2
0
 public virtual JSONNode Remove(JSONNode aNode)
 {
     return aNode;
 }
예제 #3
0
 public virtual void Add(JSONNode aItem)
 {
     Add("", aItem);
 }
예제 #4
0
 public virtual void Add(string aKey, JSONNode aItem)
 {
 }
예제 #5
0
 public override JSONNode Remove(JSONNode aNode)
 {
     try
     {
         var item = m_Dict.Where(k => k.Value == aNode).First();
         m_Dict.Remove(item.Key);
         return aNode;
     }
     catch
     {
         return null;
     }
 }
예제 #6
0
 public override void Add(string aKey, JSONNode aItem)
 {
     if (!string.IsNullOrEmpty(aKey))
     {
         if (m_Dict.ContainsKey(aKey))
             m_Dict[aKey] = aItem;
         else
             m_Dict.Add(aKey, aItem);
     }
     else
         m_Dict.Add(Guid.NewGuid().ToString(), aItem);
 }
예제 #7
0
 public override JSONNode Remove(JSONNode aNode)
 {
     m_List.Remove(aNode);
     return aNode;
 }
예제 #8
0
 public override void Add(string aKey, JSONNode aItem)
 {
     m_List.Add(aItem);
 }
예제 #9
0
 private void Set(JSONNode aVal)
 {
     if (m_Key == null)
     {
         m_Node.Add(aVal);
     }
     else
     {
         m_Node.Add(m_Key, aVal);
     }
     m_Node = null; // Be GC friendly.
 }
예제 #10
0
 public override void Add(string aKey, JSONNode aItem)
 {
     var tmp = new JSONClass();
     tmp.Add(aKey, aItem);
     Set(tmp);
 }
예제 #11
0
 public override void Add(JSONNode aItem)
 {
     var tmp = new JSONArray();
     tmp.Add(aItem);
     Set(tmp);
 }
예제 #12
0
 public JSONLazyCreator(JSONNode aNode, string aKey)
 {
     m_Node = aNode;
     m_Key = aKey;
 }
예제 #13
0
 public JSONLazyCreator(JSONNode aNode)
 {
     m_Node = aNode;
     m_Key  = null;
 }