How to encode json with order key likes Ojson ? #592
-
Hello, I have a trouble when encode_json, I want the object keys to be sorted in the same original order likes ojson.
Output:
I want output like this:
Thanks. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
Nevermind, i found the solution. |
Beta Was this translation helpful? Give feedback.
-
@hiepsahplydia, could I ask what is your solution :-) The best I could do is by using the internal implementation class #include <jsoncons/json.hpp>
#include <iostream>
struct SexyAnimation {
std::string version;
uint8_t frame_rate = 10;
int position = 0;
int size = 0;
explicit SexyAnimation() = default;
~SexyAnimation() = default;
};
JSONCONS_ALL_MEMBER_TRAITS(SexyAnimation, version, frame_rate, position, size);
int main()
{
std::error_code ec;
SexyAnimation val;
std::string buffer;
jsoncons::json_string_encoder encoder{buffer};
jsoncons::encode_traits<SexyAnimation, char>::encode(val, encoder, jsoncons::ojson{}, ec);
std::cout << buffer << "\n";
} Output:
I agree that the |
Beta Was this translation helpful? Give feedback.
Nevermind, i found the solution.