Я пытаюсь разобрать файл json ниже:
[
{
"date": "Mon 24 Dec 7:47:37 2018",
"toRecipient": "Jai",
"subject": "Hi Jai",
"body": "This is Tony",
"fromRecipient": "Tony"
},
{
"date": "Mon 24 Dec 7:47:38 2018",
"toRecipient": "Jai",
"subject": "Hi Jai 2",
"body": "This is Tony 2",
"fromRecipient": "Tony"
},
etc...
И это моя функция для разбора:
MessageLibrary::MessageLibrary(string jsonFileName) {
Json::Reader reader;
Json::Value root;
std::ifstream json(jsonFileName.c_str(), std::ifstream::binary);
bool parseSuccess = reader.parse(json, root, false);
if (parseSuccess) {
Json::Value::Members mbr = root.getMemberNames();
for(vector<string>::const_iterator i = mbr.begin(); i!= mbr.end(); i++) {
Json::Value jsonMessage = root[*i];
string date = jsonMessage["date"].asString();
string toRecipient = jsonMessage["toRecipient"].asString();
string subject = jsonMessage["subject"].asString();
string body = jsonMessage["body"].asString();
string fromRecipient = jsonMessage["fromRecipient"].asString();
// create Message objects from parse
Message *message = new Message(toRecipient, fromRecipient, subject, body, date);
messages[*i] = *message;
}
Кажется, что появляется ошибка, когда я звоню Json::Value::Members mbr = root.getMemberNames();
и я не уверен, как обойти это.
прекращение вызова после броска экземпляра 'Json :: LogicError'
what (): в Json :: Value :: getMemberNames(), значение должно быть objectValue Прервано (ядро сброшено)