Skip to content

Commit

Permalink
docs: perf minor issues
Browse files Browse the repository at this point in the history
  • Loading branch information
MistEO committed Jan 25, 2024
1 parent aa8624e commit 96af3de
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 18 deletions.
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ struct Outter
MEO_JSONIZATION(outter_a, my_vec);
};
Outter o;
o.my_vec.emplace_back(mine);
json::value j_o = o;
// output: {"my_vec":[{"map":{"key_1":[{"inner_key_1":[7,8,9]},{"inner_key_2":[10]}]},"vec":[0.500000],"x":0}],"outter_a":10}
std::cout << j_o << std::endl;
Outter outter;
outter.my_vec.emplace_back(mine);
json::value j_outter = outter;
// output:
// {"my_vec":[{"map":{"key_1":[{"inner_key_1":[7,8,9]},{"inner_key_2":[10]}]},"vec":[0.500000],"x":0}],"outter_a":10}
std::cout << j_outter.to_string() << std::endl;
// 同样的反序列化
Outter new_o = (Outter)j_o;
Outter new_o = (Outter)j_outter;
```

对于可选字段,我们可以在其中添加 `MEO_OPT`,这样在转换时,如果此字段在 JSON 中不存在,它将被跳过。
Expand Down
15 changes: 9 additions & 6 deletions README_en.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,17 @@ struct Outter
MEO_JSONIZATION(outter_a, my_vec);
};
Outter o;
o.my_vec.emplace_back(mine);
json::value j_o = o;
// output: {"my_vec":[{"map":{"key_1":[{"inner_key_1":[7,8,9]},{"inner_key_2":[10]}]},"vec":[0.500000],"x":0}],"outter_a":10}
std::cout << j_o << std::endl;
Outter outter;
outter.my_vec.emplace_back(mine);
json::value j_outter = outter;
// output:
// {"my_vec":[{"map":{"key_1":[{"inner_key_1":[7,8,9]},{"inner_key_2":[10]}]},"vec":[0.500000],"x":0}],"outter_a":10}
std::cout << j_outter.to_string() << std::endl;
// same deserialization
Outter new_o = (Outter)j_o;
Outter new_o = (Outter)j_outter;
```

For optional fields, we can add `MEO_OPT` to it, so that when converting, if this fields does not exist in json, it will be skipped.
Expand Down
14 changes: 8 additions & 6 deletions sample/sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ void serializing()

// yes, it’s that intuitive and smooth!
json::value j_mine = mine;

// output: {"map":{"key_1":[{"inner_key_1":[7,8,9]},{"inner_key_2":[10]}]},"vec":[0.500000],"x":0}
std::cout << j_mine << std::endl;

Expand All @@ -101,15 +101,17 @@ void serializing()
MEO_JSONIZATION(outter_a, my_vec);
};

Outter o;
o.my_vec.emplace_back(mine);
json::value j_o = o;
Outter outter;
outter.my_vec.emplace_back(mine);

json::value j_outter = outter;

// output:
// {"my_vec":[{"map":{"key_1":[{"inner_key_1":[7,8,9]},{"inner_key_2":[10]}]},"vec":[0.500000],"x":0}],"outter_a":10}
std::cout << j_o.to_string() << std::endl;
std::cout << j_outter.to_string() << std::endl;

// same deserialization
Outter new_o = (Outter)j_o;
Outter new_o = (Outter)j_outter;

/* For optional fields, we can add `MEO_OPT` to it, so that when converting, if this fields does not exist in json,
* it will be skipped. */
Expand Down

0 comments on commit 96af3de

Please sign in to comment.