//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 07JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Produce a JSONArray containing the names of the elements of this * JSONObject. * @return A JSONArray containing the key strings, or null if the JSONObject * is empty. */ public JSONArray Names() { var ja = new JSONArray(); var keyset = Keys(); foreach (var o in keyset) { ja.Put(o); } return ja.Length() == 0 ? null : ja; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 07JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Produce a JSONArray containing the values of the members of this * JSONObject. * @param names A JSONArray containing a list of key strings. This * determines the sequence of the values in the result. * @return A JSONArray of values. * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray ToJSONArray(JSONArray names) { if (names == null || names.Length() == 0) { return null; } var ja = new JSONArray(); for (var i = 0; i < names.Length(); i += 1) { ja.Put(Opt(names.GetString(i))); } return ja; }
//////////////////////////////////////////////////////////////////////////// //--------------------------------- REVISIONS ------------------------------ // Date Name Tracking # Description // --------- ------------------- ------------- ---------------------- // 07JUN2009 James Shen Initial Creation //////////////////////////////////////////////////////////////////////////// /** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. * @param names A JSONArray containing a list of key strings. These will be * paired with the values. * @return A JSONObject, or null if there are no names or if this JSONArray * has no values. * @ If any of the names are null. */ public JSONObject ToJSONObject(JSONArray names) { if (names == null || names.Length() == 0 || Length() == 0) { return null; } var jo = new JSONObject(); for (int i = 0; i < names.Length(); i += 1) { jo.Put(names.GetString(i), Opt(i)); } return jo; }