-
-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Closed
Description
I need a result like this:
{
"result": "success",
"num_messages": 45,
"messages":
[
{
"message": "beep boop",
"timestamp": 39348
},
{
"message": "blib blub",
"timestamp": 69420
},
//...
]
}
I have the class LogHistory::LogEntry (class inside of another class) and LogHistory provides a static getter for an std::vector<LogEntry*>*
All fine and good for normal iterating, but how do i put this thing into a json?
I tried the to_json(json& j, LogEntry& le) conversion method, but i just get "no suitable conversion method found"
Both of these two get underlined red with "no suitable conversion method found"
json j = LogHistory::GetLogHistory()->at(3);
json j = *LogHistory::GetLogHistory()->at(3);
I think i may have placed the conversion method in the wrong namespace? Right now it's a static member of LogEntry...
Here is my class structure again for clarity...
class LogHistory
{
public:
class LogEntry
{
public:
std::string message;
int timestamp;
static void to_json(Json& j, const LogEntry& le)
{
j = {{"message", le.message}, {"timestamp", le.timestamp}};
}
};
static std::vector<LogEntry*>* GetLogHistory() { return logHistory; }
private:
static std::vector<LogEntry*>* logHistory;
};
Would be very happy if someone could point me in the right direction
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels