Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Redis补充道:\&引用;到JSON字符串_Json_Redis_Backslash - Fatal编程技术网

Redis补充道:\&引用;到JSON字符串

Redis补充道:\&引用;到JSON字符串,json,redis,backslash,Json,Redis,Backslash,我正在使用ServiceStack Redis保存JSON的值,并在以后检索它。 问题是,当我从redis检索值时,它会添加多个“\”,这会破坏我的JSON 例如,我保存: {“用户”:“123456”,“密码”:“xxxxxxx”} 当我检索到值时,它会出来: {\'user\':\'123456\',\'password\':\'xxxxxxx\'} 我想知道是否有某种设置可以防止这种情况?为什么会这样? JSON包含一些“\n”字符,这些字符也被添加到了“\”中,我只是从示例中删除了它们以

我正在使用ServiceStack Redis保存JSON的值,并在以后检索它。 问题是,当我从redis检索值时,它会添加多个“\”,这会破坏我的JSON

例如,我保存:

{“用户”:“123456”,“密码”:“xxxxxxx”}

当我检索到值时,它会出来:

{\'user\':\'123456\',\'password\':\'xxxxxxx\'}

我想知道是否有某种设置可以防止这种情况?为什么会这样?
JSON包含一些“\n”字符,这些字符也被添加到了“\”中,我只是从示例中删除了它们以使其更具可读性。

检查完我的代码后,我注意到在从Redis返回数据(以字节数组的形式返回)时,我正在将其类型转换为字符串,并且它添加了额外的“\”。
我的解决方案是先将我的JSON解码为Base64字符串,然后再将其存储在Redis中,然后再将其解码回来。

ServiceStack Redis客户端将复杂类型序列化为JSON,如果要按原样存储字符串,则应仅使用而不是通用的
T
类型,例如:

void SetAll(IEnumerable<string> keys, IEnumerable<string> values);
void SetAll(Dictionary<string, string> map);
void SetValues(Dictionary<string, string> map);

void SetValue(string key, string value);
void SetValue(string key, string value, TimeSpan expireIn);
bool SetValueIfNotExists(string key, string value);
bool SetValueIfExists(string key, string value);

string GetValue(string key);
string GetAndSetValue(string key, string value);

List<string> GetValues(List<string> keys);
void SetAll(IEnumerable键、IEnumerable值);
void SetAll(字典映射);
无效设置值(字典映射);
void SetValue(字符串键、字符串值);
void SetValue(字符串键、字符串值、TimeSpan expireIn);
bool SetValueIfNotExists(字符串键、字符串值);
bool SetValueIfExists(字符串键、字符串值);
字符串GetValue(字符串键);
字符串GetAndSetValue(字符串键、字符串值);
列出GetValue(列表键);

你能添加你的代码吗?您好@Cludch在返回我的代码到这里获取代码后,我注意到我正在将redis的结果转换为字符串(redis以字节数组的形式返回值),这可能就是它添加所有这些“\”的原因,在一些测试之后,我将在这里发布正式结果。在这个问题上花了两天时间。在bash64中存储有一个缺点,即您无法通过任何工具查看缓存中的数据。非常抱歉,代码驻留在我不再工作或无法访问的公司的服务器中…/: