Pastebin launched a little side project called VERYVIRAL.com, check it out ;-) Want more features on Pastebin? Sign Up, it's FREE!
Guest

JSON checking

By: a guest on Jul 6th, 2013  |  syntax: C++  |  size: 0.79 KB  |  views: 78  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. #include "Serialize/json.h"
  2. #include "Serialize/JsonSerializer.h"
  3. #include <vector>
  4. #include <string>
  5.  
  6. struct A
  7. {
  8.     int         newMember;
  9.     std::string newMember2;
  10. };
  11.  
  12. JsonSerializeTraits_MAKE(void, A, newMember, newMember2)
  13.  
  14. int main()
  15. {
  16.     A        value;
  17.  
  18.     std::stringstream   x("{\"newMember\": 100, \"newMember2\": \"hello\"}");
  19.     x >> ThorsAnvil::Serialize::jsonImport(value);
  20.  
  21.     A       copy    = value;
  22.     copy.newMember2 = "bye";
  23.  
  24.    assert(value.newMember  == copy.newMember );
  25.    assert(value.newMember2 != copy.newMember2);
  26.  
  27.    std::cout << ThorsAnvil::Serialize::jsonExport(value) << "\n";
  28.    std::cout << ThorsAnvil::Serialize::jsonExport(copy)  << "\n";
  29. }
  30.  
  31. > ./a.out
  32. {"newMember":100,"newMember2":"hello"}
  33. {"newMember":100,"newMember2":"bye"}
  34. >