Пример #1
0
        // =========================================================================================================================
        /// <summary>
        /// Returns a specific field of the given JSON object.
        /// To return a given field of a sub key use the . format.
        ///   Example
        ///   - Return the data field:   data
        ///   - Return the id field of the data element:   data.id
        /// </summary>
        /// <param name="json">The JSON string to parse</param>
        /// <param name="fieldName">The specific field or subfield you want JSON for in dot notation.  field.subfield.subsubfield....</param>
        /// <returns>JSON representation of the specified field.</returns>
        public List <string> ConvertJSONArrayToList(string json, string fieldName)
        {
            JToken        token = null;
            List <string> data;

            try {
                token = JObject.Parse(json);
            }
            catch (JsonReaderException j) {
                string msg = string.Format("Vault: Unable to parse JSON to determine if it has any fields - Original JSON Text follows: {0}", json);

                throw new JsonReaderException(msg, j);
            }

            // Now parse fields
            try {
                foreach (string queryComponent in fieldName.Split('.'))
                {
                    token = token [queryComponent];
                }

                if (token == null)
                {
                    string msg = "Field " + fieldName + " not found.";
                    throw new VaultFieldNotFoundException(msg);
                }

                string js = token.ToString();
                data = VaultUtilityFX.ConvertJSON <List <string> > (js);
                return(data);
            }


            catch (Exception) { throw new MissingFieldException("ConvertJSONArrayToList method unable to find the field: " + fieldName); }
        }
Пример #2
0
 /// <summary>
 /// Returns the name and path parts of the provided 2 arguments.  IF the path is empty AND the name
 /// is a path plus the name, then they are separated out, otherwise the parameters are returned, minus
 /// leading and trailing slashes.
 /// </summary>
 /// <param name="name">The name parameter</param>
 /// <param name="path">The path parameter</param>
 /// <returns></returns>
 public static(string path, string name) GetNameAndPathFromValuesTuple (string name, string path = "") {
     string tempName = name.Trim('/');
     if (tempName.Contains("/"))
     {
         if (path != string.Empty) throw new ArgumentException("The Name parameter must not contain any path arguments, if the path parameter has a value");
         return VaultUtilityFX.GetNameAndPathTuple(name);
     }
     else {
         return (path.Trim('/'), tempName);
     }
 }