Skip to content

Instantly share code, notes, and snippets.

@OlegJakushkin
Last active April 29, 2017 03:06
Show Gist options
  • Save OlegJakushkin/4013a9b988c476581b0e0bd9a4d6fcf1 to your computer and use it in GitHub Desktop.
Save OlegJakushkin/4013a9b988c476581b0e0bd9a4d6fcf1 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <string>
#include <pico.h>
using namespace std;
struct apple {
int weight;
string type;
template<class Archive>
void json(Archive & ar)
{
ar & picojson::convert::member("type", type);
ar & picojson::convert::member("weight", weight);
}
};
struct busket {
std::vector<apple> apples;
template<class Archive>
void json(Archive & ar)
{
ar & picojson::convert::member("apples", apples);
}
};
int main() {
busket busket;
apple rose;
rose.type = "Roze";
rose.weight = 333;
apple ganny;
ganny.type = "Granny Smith";
ganny.weight = 777;
busket.apples.push_back(rose);
busket.apples.push_back(ganny);
string s = picojson::convert::to_string(busket);
cout << "serialized string: " << s << endl;
busket other_busket;
picojson::convert::from_string(s, other_busket);
cout << "deserialized apples count: "<< other_busket.apples.size() << endl;
cin.get();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment