Click here to Skip to main content
16,018,802 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi,

I have to read json file and bind it to gridview in asp.net using vb.net
And also have to update the json object by adding or removing the entities

Please help in that, I have been searching in google for the past 3 days, I couldn't get any help


Thanks
Chaitanya Basava Kumar

What I have tried:

I have searched in google, I couldn't find anything helpful. Please hel
Posted
Updated 7-Sep-18 9:25am
Comments
dan!sh 7-Sep-18 1:12am    
I just searched "read JSON file in VB.Net" and found plenty of helpful results. Have you had a look at any of them? If yes, and have tried something yourself, you should update the question with relevant code and tell where you are stuck.
F-ES Sitecore 7-Sep-18 4:12am    
You'll need to break it down into tasks and solve each task. First you need to convert the JSON to some kind of memory structure like a DataTable or a list of objects, so google things like "vb.net deserialize json to datatable". Bear in mind that json can take any structure but a gridview has to be a table so the json you are reading needs to be suitable, if it isn't you'll need to manipulate it in some way to get it into a tabular form.

Once your data is in a datatable bind it to a gridview and learn how to use the gridview edit mode to add\remove\update rows.

Once you have that sorted you next need to convert the data in the gridview back to json so google how to serialize datatable to json.

If you're googling for how to bind json to a gridview, edit the gridview and save the gridview back all in a single article then you're never going to find it, you need to break things down to smaller tasks and tackle them in turn.
Matias Lopez 7-Sep-18 9:44am    
Check this post:
https://www.codeproject.com/Articles/1108006/From-zero-to-hero-in-JSON-with-Csharp

1 solution

There's a library called Newtonsoft JSON.Net that you can use to easily serialize and serialize JSON string back and forth to C#/VB.NET object. Take a look at this article for example: Convert JSON to a DataTable with C# or VB.Net - blakepell.com[^]

The idea if to stream your JSON file to a string, and then convert that JSON string into an object. This object can be a collection, array or datatable in which you can use as data source for your GridView.

Modifying the underlying JSON file is another story as you need to parse the data from your GridView back to a JSON object or JArray, do the modification and then write the changes back to a file. Here's one example: https://www.c-sharpcorner.com/article/crud-operation-with-json-file-data-in-c-sharp/[^]

The example above is written in C#. If you are having a hard time interpreting the code, you can use this online free converter tool to translate C# to VB.NET: Code Converter C# to VB and VB to C# – Telerik[^]
 
Share this answer
 

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