Advertisement
DmitryPythonDevelop

Untitled

Apr 5th, 2020
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.71 KB | None | 0 0
  1. #include <string>
  2. #include <cstring>
  3. #include <iostream>
  4. #include <fstream>
  5. #include "json.hpp"
  6.  
  7. using namespace std;
  8. using json = nlohmann::json;
  9.  
  10. class Account
  11. {
  12.     private:
  13.         string FIO;
  14.         long INN;
  15.         string password;
  16.     public:
  17.         Account(string FIO, long INN, string password) {
  18.             this->FIO = FIO;
  19.             this->INN = INN;
  20.             this->password = password;
  21.         }
  22.         ~Account(){
  23.             return;
  24.         }
  25.  
  26.         json serialize() {
  27.             json tmp;
  28.  
  29.             tmp["FIO"] = this->FIO;
  30.             tmp["INN"] = this->INN;
  31.             tmp["password"] = this->password;
  32.  
  33.             return tmp;
  34.         }
  35. };
  36.  
  37.  
  38.  
  39. int main()
  40. {
  41.  
  42.  
  43.     ofstream myfile1 ("test.json");
  44.  
  45.     if (myfile1.is_open())
  46.     {
  47.         Account user1 = Account("Раннев Дмитрий", 13246985, "пароль123");
  48.         Account user2 = Account("Лодж Анастасия", 13246985, "пароль123");
  49.         Account user3 = Account("Коморов Владимир", 13246985, "пароль123");
  50.         Account user4 = Account("Альберт Ошанский", 13246985, "пароль123");
  51.  
  52.         json obj1 = user1.serialize();
  53.         json obj2 = user2.serialize();
  54.         json obj3 = user3.serialize();
  55.         json obj4 = user4.serialize();
  56.  
  57.         myfile1 << obj1 << endl << obj2 << endl << obj3 << endl << obj4 << endl;
  58.  
  59.         myfile1.close();
  60.     }
  61.  
  62.  
  63.  
  64.     string line;
  65.     string text;
  66.  
  67.     ifstream myfile ("test.json");
  68.  
  69.     if (myfile.is_open())
  70.     {
  71.         while (!myfile.eof() )
  72.         {
  73.             getline (myfile,line);
  74.             text += line;
  75.         }
  76.         myfile.close();
  77.     }
  78.  
  79.     json a = json::parse(text);
  80.  
  81. return 0;
  82. }
  83.  
  84. terminate called after throwing an instance of 'nlohmann::detail::parse_error'
  85.   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