Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
how can i fill jason result come from webservice into asp gridview c# code if my webservice result like

{"Table":[{"ID":1,"Username":"saaaaa","password":"pass1"},{"ID":2,"Username":"asdasdasd","password":"pass2"}]}


What I have tried:

string myDynamicJSON = "";
           DataTable myObjectDT = JsonConvert.DeserializeObject<DataTable>(myDynamicJSON);
           grdJSON2Grid2.DataSource = myObjectDT;
           grdJSON2Grid2.DataBind();
Posted
Updated 28-Jan-21 0:47am
Comments
Richard Deeming 28-Jan-21 4:27am    
From your sample output, it's clear that you are storing user's passwords in plain text. Don't do that.

Secure Password Authentication Explained Simply[^]
Salted Password Hashing - Doing it Right[^]
sam9787 28-Jan-21 5:27am    
just example

1 solution

If you can't change the json then you'll need to create a class to hold the data that the json represents;

C#
public class MyData
{
    public DataTable Table { get; set; }
}


then

C#
MyData myObjectDT = JsonConvert.DeserializeObject<MyData>(myDynamicJSON);
grdJSON2Grid2.DataSource = MyData.Table;
grdJSON2Grid2.DataBind();


If you can change the json that is returned then get rid of the root "Table" property and make the json
[{"ID":1,"Username":"saaaaa","password":"pass1"},{"ID":2,"Username":"asdasdasd","password":"pass2"}]


the and code you already have should work.
 
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