Reputation: 35
what is the simplest way to parse data(C++) from my text file and store it to variables? I have a parse_data.txt with this text:
{"song":"Holiday","artist":"Green Day","Album":"American Idiot","Service":"Spotify"}
I need store Holiday to song variable, Green Day to artist variable...
so QString song = Holiday...
Can someone show me some examples?
Upvotes: 0
Views: 235
Reputation: 71
Can we assume that you are using QT? If so, there is an response here that can show you an example on how to use here
Here is how you can apply to your code
QString jsonString = [your json string represenation];
QJsonDocument jsonResponse = QJsonDocument::fromJson(jsonString.toUtf8());
QJsonObject jsonObject = jsonResponse.object();
QJsonValue jsonValue = jsonObject["song"];
QString strValue = jsonValue.toString();
Upvotes: 1