-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDataReader.cpp
More file actions
33 lines (28 loc) · 939 Bytes
/
DataReader.cpp
File metadata and controls
33 lines (28 loc) · 939 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
//
// Created by victorljli on 2023/12/20.
//
#include "DataReader.h"
void DataReader::ReadFelixnEntity(std::vector<FelixnEntity> &result, int limit = -1) {
std::ifstream ifs(path.c_str());
if (!ifs.is_open()) {
std::cout << "Open data json file fail." << std::endl;
return;
}
Json::Reader jsonReader;
std::string line;
while (std::getline(ifs, line)) {
if (limit > 0 && result.size() >= limit) {
break;
}
std::istringstream iss(line);
Json::Value rootValue;
if (jsonReader.parse(iss, rootValue)) {
FelixnEntity entity(rootValue["id"].asString(), rootValue["name"].asString(),
rootValue["fullPath"].asString(), rootValue["size"].asInt64());
result.push_back(entity);
} else {
std::cout << "Parse data json file fail." << std::endl;
}
}
ifs.close();
}