Click here to Skip to main content
15,917,538 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have to save data in a JSON file. the data has to be inserted under a existing category. I am not able to write the data under the required category, instead it is coming as a seperate one. Please find the code below.
"CategoryName": [{
	"SubCategoryName": "Test2",
	"HostName": "111.222.225.15",
	"UserName": "AAAA",
	"Password": "AAAA",
	"IsActive": true
},
{
	"SubCategoryName": "test 1",
	"HostName": "11.11.11.11",
	"UserName": "3333",
	"Password": "33333",
	"IsActive": false
}]

I want to add a third Sub Category, but i am unable to do it?

What I have tried:

I have tried to read the data from the existing json file and assign it to a object and tried to write into the file again.
I am not able to write the new data into the file.
Posted
Updated 8-Sep-17 2:59am
v2

1 solution

Convert to classes, Add the extra data, then convert back and save the JSON. This article will show you how: Working with JSON in C# & VB[^]
 
Share this answer
 
Comments
Prakash Sekhar 11-Sep-17 2:17am    
I went through the link which u had posted but i am not able to get it work correctly.
1. How to convert to classes and then add the new data. Can you explain more?
Graeme_Grant 11-Sep-17 2:21am    
What do you want me to explain? Did you download the code? There are 6 different projects in the solution that are used in the article. All projects are fully working.

The article also explains how to convert JSON data into classes.
Prakash Sekhar 11-Sep-17 2:55am    
I have downloaded the 3 solutions. I am not able to understand the implementation properly.
Graeme_Grant 11-Sep-17 3:58am    
You followed the first example? JSON Utils[^] to generate the classes? If you have, I show you how to load the JSON from a file and how to convert it to the generated classes - 2 lines of code with the helper class. What is not to understand?
Prakash Sekhar 11-Sep-17 5:23am    
i have generated the classes using JSON utils. I have the class file. What i need to do next?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900