Advertisement
Guest User

Untitled

a guest
Jun 27th, 2019
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.72 KB | None | 0 0
  1. {
  2. "id": "test@gmail.com",
  3. "active": 1,
  4. "is_logged": true,
  5. "token": "hsja3t56yJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRlc3RAZHZlby5jb20iLCJwYXNzd29yZCI6InRlc3QyMDE4KyIsImV4cGlyZU9uIjoiMjAxOS0wNi0yMVQwNTozNzowOC4xODhaIn0.3wgGeL_HvcoEJJeEF7tj8jeXk2uIKpOoi9ewmK5yhteh",
  6. "status": "OK",
  7. "usertype": "TestUser",
  8. "msg": "Login Successfull."
  9. }
  10.  
  11. string[] sep = response.Split(',');
  12.  
  13. foreach (string any in sep)
  14. Console.WriteLine(any);
  15.  
  16. //string[] colon = sep[0].Split(':');
  17. string[][] colon = sep.Select(x => x.Split(':')).ToArray();
  18.  
  19. //int count = colon.Count();
  20. for (int i = 0; i <= colon.Length; i++)
  21. {
  22. Console.WriteLine(colon[i][0]);
  23. Console.WriteLine(colon[i][1]);
  24. }
  25.  
  26. public class UserData
  27. {
  28. public string id { get; set; }
  29. public int active { get; set; }
  30. public bool is_logged { get; set; }
  31. public string token { get; set; }
  32. public string status { get; set; }
  33. public string usertype { get; set; }
  34. public string msg { get; set; }
  35. }
  36.  
  37. string response = "{"id":"test @gmail.com","active":1,"is_logged":true,"token":"hsja3t56yJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InRlc3RAZHZlby5jb20iLCJwYXNzd29yZCI6InRlc3QyMDE4KyIsImV4cGlyZU9uIjoiMjAxOS0wNi0yMVQwNTozNzowOC4xODhaIn0.3wgGeL_HvcoEJJeEF7tj8jeXk2uIKpOoi9ewmK5yhteh","status":"OK","usertype":"TestUser","msg":"Login Successfull."}";
  38. var responseData = JsonConvert.DeserializeObject<UserData>(response);
  39.  
  40. //here the print in JSON Data
  41.  
  42. Console.WriteLine("id : " + responseData.id);
  43. Console.WriteLine("active : " + responseData.active);
  44. Console.WriteLine("is_logged : " + responseData.is_logged);
  45. Console.WriteLine("token : " + responseData.token);
  46. Console.WriteLine("status : " + responseData.status);
  47. Console.WriteLine("usertype : " + responseData.usertype);
  48. Console.WriteLine("msg : " + responseData.msg);
  49.  
  50. JObject jo = JObject.Parse(searchCondition);
  51.  
  52. foreach (JToken child in jo.Children()) {
  53. var prop = child as JProperty;
  54. if (prop.Value != null && !string.IsNullOrEmpty(prop.Value.ToString())) {
  55. string name=prop.Name;
  56. string value = prop.Value;
  57. //You can now do whatever with the values like put in a list of object
  58. }
  59. }
  60.  
  61. using System;
  62. using Newtonsoft.Json.Linq;
  63.  
  64. public class Program
  65. {
  66. public static void Main()
  67. {
  68. string jsonString = "{"firstname":"Alex Wu","lastname":"type"}";
  69. JObject jObject = JObject.Parse(jsonString);
  70. string firstname = (string)jObject.SelectToken("firstname");
  71. string lastname = (string)
  72. Console.WriteLine("{0}", firstname);
  73. Console.ReadLine();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement