For this we need a JSON object to pass into our program. Following web site provides set of JSON objects in their site. Let's use one of them.
Follow the above link. Go to "Guide" tab. In the bottom of the page you can see multiple data sets. I'll use the below data set which has 5 data fields.
Copy Raw Data set to a text file and save it. We will be using the file path to access it.
In this article I will use .NET JavaScriptSerializer class. This is not the only method you can do this. I will explain other methods in another blog post.
You need to create a class to convert the JSON object into C# object. In that class, number of fields and the type of data fields should be equal to JSON object's data fields. In our JSON object there are five data fields.
We need to create a C# class according to this.
Then you need to create a JavaScriptSerializer object. To access this class add System.Web.Extensions reference to the solution.
By giving the JSON file you saved previously, deserialize the JSON object into C# object using JavaScriptSerializer.
| Data Field | Data Type |
|---|---|
| postId | int |
| id | int |
| name | sting |
| sting | |
| body | sting |
We need to create a C# class according to this.
You can test C# object's properties by printing them.
You're done.If you have any comments post here :)











