コード例 #1
0
        /**
         * Returns a new object whose values are the values in this array, and whose
         * names are the values in {@code names}. Names and values are paired up by
         * index from 0 through to the shorter array's length. Names that are not
         * strings will be coerced to strings. This method returns null if either
         * array is empty.
         */
        public JsonObject ToJSONObject(JsonArray names)
        {
            JsonObject result = new JsonObject();
            int        length = Math.Min(names.Length(), values.Count);

            if (length == 0)
            {
                return(null);
            }
            for (int i = 0; i < length; i++)
            {
                String name = Json.ToString(names.Opt(i));
                result.Put(name, Opt(i));
            }
            return(result);
        }
コード例 #2
0
        /**
         * Returns an array with the values corresponding to {@code names}. The
         * array contains null for names that aren't mapped. This method returns
         * null if {@code names} is either null or empty.
         */
        public JsonArray ToJSONArray(JsonArray names)
        {
            JsonArray result = new JsonArray();

            if (names == null)
            {
                return(null);
            }
            int length = names.Length();

            if (length == 0)
            {
                return(null);
            }
            for (int i = 0; i < length; i++)
            {
                string name = Json.ToString(names.Opt(i));
                result.Put(Opt(name));
            }
            return(result);
        }