Beispiel #1
0
        /// <summary>
        /// Append an array of JSONObjects to current object
        /// </summary>
        /// <param name="names"></param>
        /// <returns></returns>
        public JSONArray toJSONArray(JSONArray names)
        {
            if (names == null | names.Length() == 0)
                return null;

            JSONArray ja = new JSONArray();
            for (int i = 0; i < names.Length(); i++)
            {
                ja.put(this.opt(names.getString(i)));
            }
            return ja;
        }
Beispiel #2
0
 /// <summary>
 /// Produce a JSONObject by combining a JSONArray of names with the values
 /// of this JSONArray.
 /// </summary>
 /// <param name="names">
 /// A JSONArray containing a list of key strings. These will be paired with the values.
 /// </param>
 /// <returns>A JSONObject, or null if there are no names or if this JSONArray</returns>
 public JSONObject toJSONObject(JSONArray names)
 {
     if (names == null || names.Length() == 0 || this.Length() == 0)
     {
         return null;
     }
     JSONObject jo = new JSONObject();
     for (int i=0; i <names.Length(); i++)
     {
         jo.put(names.getString(i),this.opt(i));
     }
     return jo;
 }
Beispiel #3
0
        /// <summary>
        /// Produce a JSONArray containing the names of the elements of this JSONObject
        /// </summary>
        /// <returns>A JSONArray containing the key strings, or null if the JSONObject</returns>
        public JSONArray names()
        {
            JSONArray ja = new JSONArray();

            //NOTE!! I choose to use keys stored in the ArrayList, to maintain sequence order
            foreach (string key in myKeyIndexList)
            {
                ja.put(key);
            }
            if (ja.Length() == 0)
            {
                return null;
            }
            return ja;
        }