#include "json.hpp"
using json = nlohmann::json;
struct Image
{
std::string url;
int width;
int height;
Image(){
url = "";
width = -1;
height = -1;
};
Image(std::string url,int width, int height):
url(url),width(width),height(height){}
};
namespace ns {
// a simple struct to model a person
struct session {
std::vector<Image> ImageUrls;
std::string msg;
int code;
struct returnBody {
int ComicId;
}body;
struct bboxes
{
std::string cords;
}box;
};
void to_json(json& j, const session& s);
void from_json(const json& j, session& s);
}
void ns::to_json(json& j, const ns::session& s) {
j = json{
{"ImageUrls", {json::parse(s.ImageUrls)}},
{"msg", s.msg},
{"code", s.code},
{"returnBody", {
{"ComicId", s.body.ComicId}}
},
{"result", {
{"boxes", s.box.cords}}
}
};
}
void ns::from_json(const json& j, ns::session& s) {
j.at("ImageUrls").get_to(s.ImageUrls);
j.at("msg").get_to(s.msg);
j.at("code").get_to(s.code);
j.at("returnBody").at("ComicId").get_to(s.body.ComicId);
j.at("result").at("boxes").get_to(s.box.cords);
}
I'd like to parse the json fromat like this
But my
to_jsonandfrom_jsonpart runs into error. Would U please tell me how to realize this part?Mostly
vector<struct>part.Thanks
Which version of the library did you use?
developbranch