Ejemplo n.º 1
0
        private string GetValue(ExpressionModel key, bool privateFirst)
        {
            try
            {
                var res = Get(key.Key, privateFirst);
                if (res != null)
                {
                    return(res);
                }

                string currentKey = key.CurrentKey;
                if (key.IsArray)
                {
                    currentKey = key.ArrayKey;
                }
                res = Get(currentKey, privateFirst);
                if (res == null)
                {
                    return(string.Empty);
                }

                var arg = res;
                if (key.SubExpression == null)
                {
                    if (key.IsArray)
                    {
                        JArray arr = JsonHelper.GetArray(arg, currentKey);
                        if (key.Index >= arr.Count)
                        {
                            return(string.Empty);
                        }
                        else
                        {
                            return(arr[key.Index].ToString());
                        }
                    }
                    else
                    {
                        return(arg);
                    }
                }
                else
                {
                    if (key.IsArray)
                    {
                        JArray arr   = JsonHelper.GetArray(arg, currentKey);
                        var    token = JsonHelper.FindToken(arr[key.Index], key.SubExpression.Key, currentKey);
                        return(token?.ToString());
                    }
                    else
                    {
                        JObject o     = JsonHelper.GetObject(arg, currentKey);
                        var     token = JsonHelper.FindToken(o, key.SubExpression.Key, currentKey);
                        return(token?.ToString());
                    }
                }
            }
            catch
            {
                return(key.Key);
            }
        }