Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <string>
- #include <cstring>
- #include <iostream>
- #include <fstream>
- #include "json.hpp"
- using namespace std;
- using json = nlohmann::json;
- class Account
- {
- private:
- string FIO;
- long INN;
- string password;
- public:
- Account(string FIO, long INN, string password) {
- this->FIO = FIO;
- this->INN = INN;
- this->password = password;
- }
- ~Account(){
- return;
- }
- json serialize() {
- json tmp;
- tmp["FIO"] = this->FIO;
- tmp["INN"] = this->INN;
- tmp["password"] = this->password;
- return tmp;
- }
- };
- int main()
- {
- ofstream myfile1 ("test.json");
- if (myfile1.is_open())
- {
- Account user1 = Account("Раннев Дмитрий", 13246985, "пароль123");
- Account user2 = Account("Лодж Анастасия", 13246985, "пароль123");
- Account user3 = Account("Коморов Владимир", 13246985, "пароль123");
- Account user4 = Account("Альберт Ошанский", 13246985, "пароль123");
- json obj1 = user1.serialize();
- json obj2 = user2.serialize();
- json obj3 = user3.serialize();
- json obj4 = user4.serialize();
- myfile1 << obj1 << endl << obj2 << endl << obj3 << endl << obj4 << endl;
- myfile1.close();
- }
- string line;
- string text;
- ifstream myfile ("test.json");
- if (myfile.is_open())
- {
- while (!myfile.eof() )
- {
- getline (myfile,line);
- text += line;
- }
- myfile.close();
- }
- json a = json::parse(text);
- return 0;
- }
- terminate called after throwing an instance of 'nlohmann::detail::parse_error'
- what(): [json.exception.parse_error.101] parse error at line 1, column 82: syntax error while parsing value - unexpected '{'; expected end of input
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement