Jay*_*ens 8 json stackexchange.redis
我有一个RedisValue[]从StackExchange.Redis客户端返回的数组.我想获取JSON数组中的每个值(实际上是字符串)并将它们连接在一起以获得JSON可以返回给客户端的有效字符串.
这就是我想要做的......
var results = redis.HashGet("srch", ArrayOfRedisKeys[]);
string returnString = "[" + string.Join(results, ",") + "]";
Run Code Online (Sandbox Code Playgroud)
但是,这不起作用,因为它results是一个RedisValue不是数组的数组string.除了迭代RedisValue数组之外,还有一种直接且高效的方法吗?
Mar*_*ell 14
目前还没有,但我刚刚将以下扩展方法推送到ExtensionMethods.cs:
static readonly string[] nix = new string[0];
/// <summary>
/// Create an array of strings from an array of values
/// </summary>
public static string[] ToStringArray(this RedisValue[] values)
{
if (values == null) return null;
if (values.Length == 0) return nix;
return Array.ConvertAll(values, x => (string)x);
}
Run Code Online (Sandbox Code Playgroud)
所以:在下一个版本中,你可以使用results.ToStringArray().在此之前,您可以在本地复制上述内容.
| 归档时间: |
|
| 查看次数: |
4955 次 |
| 最近记录: |