Click here to Skip to main content
15,881,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have assigned string, integer and enum value to json object.
I need to get back the original value from jso object.
I am getting problem when converting json value to enum type.
C++
enum Topic{ BOOK, PEN, PENCIL};
Json::Value record;

record["hello"] = "world";
record["number"] = 2;
record["topic"] = Topic; // no error

std::string str = record["hello"].asString();
int val = record["number"].asInt();

enum TopicType = record["topic"]; // Error


What I have tried:

enum Topic{ BOOK, PEN, PENCIL};
Json::Value record;

record["hello"] = "world";
record["number"] = 2;
record["topic"] = Topic; // no error

std::string str = record["hello"].asString();
int val = record["number"].asInt();

enum TopicType = record["topic"]; // Error
Posted
Updated 1-Sep-21 4:57am
v2
Comments
Member 14036158 2-Sep-21 11:24am    
Thanks for the suggestion.

1 solution

C++
Topic type = record["topic"]; 
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900