Ejemplo n.º 1
0
        /// <summary>
        /// JSONNode解析后转为Normal
        /// </summary>
        /// <param name="json">A JSON string.</param>
        /// <returns>An ArrayList, a Hashtable, a double, a string, null, true, or false</returns>
        public static object Parse(string json)    //91ms
        {
            object ret = null;

            Johny.JSONNode jnode = null;
            try
            {
                jnode = Johny.JSONNode.Parse(json);
            }
            catch (NullReferenceException e)
            {
                EB.Debug.LogError(e.ToString());
                return(null);
            }

            if (jnode != null)
            {
                JSONNode2Normal(jnode, out ret);
            }

            return(ret);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// JSONNode转为Normal
        /// </summary>
        /// <param name="key"></param>
        /// <param name="jnode"></param>
        /// <param name="parent"></param>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        private static object ParseValueSimple <T>(string key, Johny.JSONNode jnode, T parent) where T : ICollection
        {
            if (jnode.IsObject)
            {
                #region parse object
                Hashtable ht      = Johny.HashtablePool.Claim(Johny.HashtablePoolType.t16);
                var       jobject = jnode.AsObject;
                foreach (var it in jobject.Children)
                {
                    ParseValueSimple(it.Key, it.Value, ht);
                }
                Johny.JSONNodePool.Release(jobject);

                if (!ParseValueSimple_AddToParent <Hashtable>(parent, key, ht))
                {
                    return(ht);
                }
                #endregion
            }
            else if (jnode.IsArray)
            {
                #region  parse array
                ArrayList al     = Johny.ArrayListPool.Claim();
                var       jarray = jnode.AsArray;
                for (int i = 0; i < jarray.Count; i++)
                {
                    ParseValueSimple(string.Empty, jarray[i], al);
                }
                Johny.JSONNodePool.Release(jarray);

                if (!ParseValueSimple_AddToParent <ArrayList>(parent, key, al))
                {
                    return(al);
                }
                #endregion
            }
            else if (jnode.IsString)
            {
                #region  parse string
                string str = jnode.ToString();
                Johny.JSONNodePool.Release(jnode);

                if (!ParseValueSimple_AddToParent <string>(parent, key, str))
                {
                    return(str);
                }
                #endregion
            }
            else if (jnode.IsNumber)
            {
                #region  parse string
                double num = jnode.AsDouble;

                if (!ParseValueSimple_AddToParent <double>(parent, key, num))
                {
                    return(num);
                }
                #endregion
            }
            else if (jnode.IsBoolean)
            {
                #region  parse bool
                bool bb = jnode.AsBool;

                if (!ParseValueSimple_AddToParent <bool>(parent, key, bb))
                {
                    return(bb);
                }
                #endregion
            }
            else if (jnode.IsNull)
            {
                if (!ParseValueSimple_AddToParent <Johny.JSONNode>(parent, key, null))
                {
                    return(null);
                }
            }

            return(null);
        }