Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

I need some help with a complex json #42

Closed
kilianp07 opened this issue Nov 23, 2020 · 2 comments
Closed

I need some help with a complex json #42

kilianp07 opened this issue Nov 23, 2020 · 2 comments

Comments

@kilianp07
Copy link

kilianp07 commented Nov 23, 2020

During my program I run a query and I get this result in a string
{ "ok": true, "result": { "message_id": 109, "from": { "id": 3456789, "is_bot": true, "first_name": "ghhdhdsh", "username": "hbdhbhbdh" }, "chat": { "id": 5678, "first_name": "ghj", "last_name": "ghj", "username": "ghj", "type": "private" }, "date": 1606112895, "text": "ddd" } }

So I created some structures
`
struct from {
int id;
bool is_bot;
string first_name;
string username;
XTOSTRUCT( O(id, is_bot,first_name,username));
};

struct chat{
int id;
string first_name;
string last_name;
string username;
string type;
XTOSTRUCT( O(id, first_name,last_name,username,type));
};

struct result: public from,chat{
int message_id;
int date;
string text;
XTOSTRUCT(I(from,chat), O(message_id, date, text));
};

struct retour: public result {
bool ok;
XTOSTRUCT(I(result), O(ok));

};
`

And I want to do something like

if (retour.ok){ cout<<retour.result.chat.username<<" has received the message"; }

How can I do that, I've got some errors.
Thank you

@xyz347
Copy link
Owner

xyz347 commented Nov 23, 2020

define struct like this:

struct From {
  int id;
  bool is_bot;
  string first_name;
  string username;
  XTOSTRUCT( O(id, is_bot,first_name,username));
};

struct Chat{
  int id;
  string first_name;
  string last_name;
  string username;
  string type;
  XTOSTRUCT( O(id, first_name,last_name,username,type));
};

struct Result {
  int message_id;
  From from;
  Chat chat;
  int  date;
  string text;
  XTOSTRUCT(O(message_id, from, chat, date, text));
};

struct retour {
  bool ok;
  Result result;
  XTOSTRUCT(O(ok, result));
};

@kilianp07
Copy link
Author

Thank you, it works fine !
Congratulations for your project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants