-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutil.cpp
More file actions
37 lines (32 loc) · 860 Bytes
/
util.cpp
File metadata and controls
37 lines (32 loc) · 860 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include "util.h"
#include <iostream>
#include <sstream>
#include <cstdlib>
Json::Value parse_json(const std::string &info) {
// 解析JSON
Json::Value root;
Json::CharReaderBuilder readerBuilder;
std::string errors;
std::istringstream jsonStream(info);
// 解析JSON字符串
bool parsingSuccessful =
Json::parseFromStream(readerBuilder, jsonStream, &root, &errors);
if (!parsingSuccessful) {
std::cerr << "Failed to parse JSON: " << errors << std::endl;
return Json::Value();
}
return root;
}
std::string rand_string(int len){
srand(static_cast<unsigned int>(time(nullptr)));
std::stringstream ss;
for(int i = 0; i < len; i++){
int t = rand()%52;
if(t<26){
ss<<'a' + t;
}else{
ss<<'A' + t;
}
}
return ss.str();
}