I was building a quizbowl tracker to keep track of different facts and definitions but my JSON formatting is not working well. When I tried it, the json file throws an error, and I do not know how to fix it. So, does anyone know how to fix this probolem?
So I want my json file to look like this
{
"sasa": "sasa\n",
"lol": "saasasa",
"smth" : "lolqsas"
}
but it does this...
{
}{
"sasa" : "sasa\n"
}
and says only one top-level item is for JSON so how do I rechange it to look like how I want it to?
heres my code
#include <iostream>
#include<fstream>
#include<string>
#include<json/writer.h>
#include <json/json.h>
using std::cout;
using std::cin;
using std::string;
class quiz_bowl
{
public:
quiz_bowl()
{
cout << "Quizbowl facts and stuff\n";
}
static void qb_file_add(std::ofstream& qb_file)
{
Json::Value event;
string term, fact, multifacts;
cout << "what term" << std::endl;
cin.ignore();
std::getline(cin, term);
cout << "what are the facts?" << std::endl;
int counter = 0;
while (std::getline(cin, fact) && !fact.empty())
{
if (fact == "stop" && counter != 0)
break;
else if (fact == "stop" && counter == 0)
cout << "Do not stop in the first line\n";
multifacts += fact + '\n';
counter++;
}
event[term] = multifacts;
qb_file << event;
cout << "The term " << term << " has been added\n";
}
};
int main()
{
cout << "say add to add something or view to view something\n";
string answer;
cin >> answer;
std::ofstream quiz_bowl_file("qb_facts.json", std::ios::app);
if (answer == "view")
cout << "viewing\n";
else if (answer == "add")
quiz_bowl::qb_file_add(quiz_bowl_file);
else
cout << "Invalid argument passed\n";
}
So how would I make the format work with the JSON file and not error by saying that top item message
Aucun commentaire:
Enregistrer un commentaire