Tuesday, 7 January 2020

Trick to Convert xml, json to C# class in Visulastudio

First create a class file say “Customer.cs” and removed all the code from it, removing the code is not necessary, if we want to create the class in some existing class even then we can use this technique, enough talked let’s create a class from our above XML or JSON.
  1. Copy one customer record i.e. <customer> to </customer>
  2. Open the customer.cs file and put the cursor where you want to create the class
  3. From Menu click Edit => Paste Special => Paste XML as Classes or Paste JSON as Classes which you want
  4. Our class is created 
e.g  (select this i mean copy this in RAM)
  1. <Customer>
  2.     <CustomerID>124</CustomerID>
  3.     <CompanyName>Hungry Coyote Import Store</CompanyName>
  4.     <ContactName>Yoshi Latimer</ContactName>   
  5.     <Phone>(503) 555-6874</Phone>
  6.   </Customer>
JSON sample is
  1. {
  2.   "Customer": {
  3.     "CustomerID": "123",
  4.     "CompanyName": "Great Lakes Food Market",
  5.     "ContactName": "Howard Snyder",   
  6. "Phone": "(503) 555-7555"   
  7.   }
  8. }

No comments:

Post a Comment

Baisic Useful Git Commands

  Pushing a fresh repository Create a fresh repository(Any cloud repository). Open terminal (for mac ) and command (windows) and type the be...