├── Read me.txt ├── Newtonsoft.Json.dll ├── README.md ├── Get_post.cs ├── JSON_obj_break.cs └── object_of_object_data_parse.cs /Read me.txt: -------------------------------------------------------------------------------- 1 | Must use newtonsoft package 2 | 3 | 4 | reference > add > search 5 | -------------------------------------------------------------------------------- /Newtonsoft.Json.dll: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MuhammadTayyab1/JSON/HEAD/Newtonsoft.Json.dll -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | must use newtonsoft package 2 | before using JSON obj breaking 3 | 4 | click on 5 | reference > add > and search newtonsoft after download 6 | -------------------------------------------------------------------------------- /Get_post.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text; 5 | using System.Collections.Specialized; 6 | 7 | namespace Examples.System.Net 8 | { 9 | 10 | public class WebRequestPostExample 11 | { 12 | public static void Main() 13 | { 14 | using (var wb = new WebClient()) 15 | { 16 | var data = new NameValueCollection(); 17 | data["username"] = "myUser"; 18 | data["password"] = "myPassword"; 19 | 20 | // Json get and post 21 | 22 | var response = wb.UploadValues("https://jsonplaceholder.typicode.com/posts", "POST", data); 23 | string responseInString = Encoding.UTF8.GetString(response); 24 | Console.WriteLine(responseInString); 25 | 26 | } 27 | 28 | using (var wb = new WebClient()) 29 | { 30 | var response = wb.DownloadString("https://jsonplaceholder.typicode.com/todos/1"); 31 | Console.WriteLine(response); 32 | } 33 | 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /JSON_obj_break.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text; 5 | using System.Collections.Specialized; 6 | using System.Collections.Generic; 7 | using Newtonsoft.Json; 8 | using System.Linq; 9 | 10 | namespace Examples.System.Net 11 | { 12 | 13 | public class WebRequestPostExample 14 | { 15 | public static void Main() 16 | { 17 | using (var wb = new WebClient()) 18 | { 19 | var data = new NameValueCollection(); 20 | // post variables 21 | data["username"] = "myUser"; 22 | data["password"] = "myPassword"; 23 | 24 | var response = wb.UploadValues("https://jsonplaceholder.typicode.com/posts", "POST", data); 25 | string responseInString = Encoding.UTF8.GetString(response); 26 | // Display 27 | Console.WriteLine(responseInString); 28 | } 29 | 30 | 31 | 32 | 33 | using (var wb = new WebClient()) 34 | { 35 | var response = wb.DownloadString("https://jsonplaceholder.typicode.com/todos/1"); 36 | Dictionary list = JsonConvert.DeserializeObject>(response.ToString()); 37 | 38 | string[] keys = list.Keys.ToArray(); 39 | 40 | Console.WriteLine("Origanal data "); 41 | Console.WriteLine("==========================="); 42 | Console.WriteLine(""); 43 | Console.WriteLine(response); 44 | Console.WriteLine("==========================="); 45 | Console.WriteLine("Breaking data "); 46 | Console.WriteLine(""); 47 | // or you can use for loop 48 | Console.WriteLine("1 ) " + list[keys[0]].ToString()); 49 | Console.WriteLine("2 ) " + list[keys[1]].ToString()); 50 | Console.WriteLine("3 ) " + list[keys[2]].ToString()); 51 | Console.WriteLine("4 ) " + list[keys[3]].ToString()); 52 | 53 | 54 | 55 | Console.WriteLine(); 56 | 57 | //Console.WriteLine(response); 58 | } 59 | 60 | } 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /object_of_object_data_parse.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text; 5 | using System.Collections.Specialized; 6 | using System.Collections.Generic; 7 | using Newtonsoft.Json; 8 | using System.Linq; 9 | using Newtonsoft.Json.Linq; 10 | 11 | namespace Examples.System.Net 12 | { 13 | 14 | public class WebRequestPostExample 15 | 16 | { 17 | public static void Main() 18 | { 19 | using (var wb = new WebClient()) 20 | { 21 | var response = wb.DownloadString("https://api.myjson.com/bins/a4vru"); 22 | 23 | Console.WriteLine(response); 24 | 25 | Dictionary test = JsonConvert.DeserializeObject>(response); 26 | 27 | string[] nam = new string[test.Keys.ToArray().Length]; 28 | string[] id = new string[test.Keys.ToArray().Length]; 29 | string[] sta = new string[test.Keys.ToArray().Length]; 30 | 31 | 32 | 33 | string[] keys = test.Keys.ToArray(); 34 | 35 | int index = 0; 36 | foreach (var item in keys) 37 | { 38 | car temp = test[item]; 39 | 40 | //Console.WriteLine(temp.Name); 41 | nam[index] = temp.Name; 42 | 43 | //Console.WriteLine(temp.Id); 44 | id[index] = temp.Id; 45 | 46 | //Console.WriteLine(temp.Status); 47 | sta[index] = temp.Status; 48 | 49 | index++; 50 | 51 | //Console.WriteLine("============="); 52 | } 53 | 54 | 55 | // checking arrays data 56 | Console.WriteLine("data in arrays "); 57 | for (int i = 0; i < 5; i++) 58 | { 59 | Console.WriteLine("============================="); 60 | Console.WriteLine("Name : " + nam[i]); 61 | Console.WriteLine("Id : " + id[i]); 62 | Console.WriteLine("Status : " + sta[i]); 63 | } 64 | 65 | } 66 | 67 | } 68 | 69 | public class car 70 | { 71 | public string Name { get; set; } 72 | public string Id { get; set; } 73 | public string Status { get; set; } 74 | 75 | } 76 | } 77 | } 78 | --------------------------------------------------------------------------------