Advertisement
Guest User

Untitled

a guest
Jul 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using System;
  2. using Newtonsoft.Json;
  3.  
  4. public class Test
  5. {
  6. public static void Main()
  7. {
  8. var testObject = new TestClass
  9. {
  10. TestString = "Test",
  11. TestInteger = 1234
  12. };
  13.  
  14. // turn class into a json string
  15. // output: { "TestString":"Test", "TestInteger": 1234 }
  16. var classSerializedToString = JsonConvert.Serialize(testObject);
  17.  
  18. // turn string back into class
  19. TestClass classFromSerializedString = JsonConvert.Deserialize(classSerializedToString);
  20. }
  21. }
  22.  
  23. public class TestClass
  24. {
  25. public string TestString { get; set; }
  26. public int TestInteger { get; set; }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement