65,187
社区成员




读数据库和读文件原理是一样的,唯一能影响结果的就是编码,我说的调一下ide 的编码不是说ide的编码和最后的结果有关系,而是想让你在调试过程中能看到字符串的拼接过程,这样你就能在调试过程中发现是哪个环节出了问题。
std::string UrlDecode(const std::string& szToDecode)
{
std::string result;
int hex = 0;
for (size_t i = 0; i < szToDecode.length(); ++i)
{
switch (szToDecode[i])
{
case '+':
result += ' ';
break;
case '%':
if (isxdigit(szToDecode[i + 1]) && isxdigit(szToDecode[i + 2]))
{
std::string hexStr = szToDecode.substr(i + 1, 2);
hex = strtol(hexStr.c_str(), 0, 16);
//字母和数字[0-9a-zA-Z]、一些特殊符号[$-_.+!*'(),] 、以及某些保留字[$&+,/:;=?@]
//可以不经过编码直接用于URL
if (!(
//(hex >= 48 && hex <= 57) || //0-9
//(hex >=97 && hex <= 122) || //a-z
//(hex >=65 && hex <= 90) || //A-Z
//一些特殊符号及保留字[$-_.+!*'(),] [$&+,/:;=?@]
hex == 0x21 || hex == 0x24 || hex == 0x26 || hex == 0x27 || hex == 0x28 || hex == 0x29
|| hex == 0x2a || hex == 0x2b|| hex == 0x2c || hex == 0x2d || hex == 0x2e || hex == 0x2f
|| hex == 0x3A || hex == 0x3B|| hex == 0x3D || hex == 0x3f || hex == 0x40 || hex == 0x5f
))
{
result += char(hex);
i += 2;
}
else result += '%';
}else {
result += '%';
}
break;
default:
result += szToDecode[i];
break;
}
}
return result;
}
我C++里面是可以的
",
"name" : "玩家088",
"ps" : "这家伙很懒,什么都没写!
# Host: 192.168.6.251 (Version 5.1.71)
# Date: 2019-03-06 16:33:18
# Generator: MySQL-Front 6.1 (Build 1.26)
#
# Structure for table "user"
#
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`Index` int(11) unsigned NOT NULL AUTO_INCREMENT,
`user_id` varchar(50) NOT NULL DEFAULT '0',
`user_name` varchar(20) NOT NULL DEFAULT '',
`pwd` varchar(20) NOT NULL DEFAULT '',
`login_time` varchar(20) NOT NULL DEFAULT '',
`level` varchar(20) NOT NULL DEFAULT '',
PRIMARY KEY (`Index`),
UNIQUE KEY `user_id` (`user_id`),
UNIQUE KEY `user_name` (`user_name`)
) ENGINE=MyISAM AUTO_INCREMENT=16 DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC;
#
# Data for table "user"
#
/*!40000 ALTER TABLE `user` DISABLE KEYS */;
INSERT INTO `user` VALUES (1,'0','肖波纳','123','201811211912',' 1'),(2,'1','郭晶敏','123','201811212118','2'),(3,'2','胡永海','123','201811212116','3'),(4,'3','柏树生','123','201811212115','4'),(5,'4','景小甜','tttt','201811212114','1'),(6,'5','马龙乒','rrrr','201811212117','1'),(7,'6','林冲宋','yyy','201811212111','1'),(8,'7','华为贵','ppp','201811212112','9');
/*!40000 ALTER TABLE `user` ENABLE KEYS */;
"name" : "玩家088",
"ps" : "这家伙很懒,什么都没写!
",jsoncpp 确实不能直接中文encode. 正确的含中文的应该编码成 "name":"\u4e2d\u6587\u540d"}
可以看这个帖子
https://bbs.csdn.net/topics/391894820
[quote=引用 7 楼 smwhotjay 的回复:]
[quote=引用 3 楼 @风轻云淡_ 的回复:]
[quote=引用 1 楼 smwhotjay 的回复:]
jsoncpp 确实不能直接中文encode. 正确的含中文的应该编码成 "name":"\u4e2d\u6587\u540d"}
可以看这个帖子
https://bbs.csdn.net/topics/391894820