I'm newbie in asp.net c# . Iwant to show the json data into table with gridview .I have json data with this format :
[{
"reviewerID": "A1YS9MDZP93857",
"asin": "0006428320",
"reviewerName": "John Taylor",
"helpful": [
0,
0
],
"reviewText": "last movement of sonata #6 is missing. What should one expect?",
"overall": 3,
"summary": "Parts missing",
"unixReviewTime": 1394496000,
"reviewTime": "03 11, 2014"
},
{
"reviewerID": "A3TS466QBAWB9D",
"asin": "0014072149",
"reviewerName": "Silver Pencil",
"helpful": [
0,
0
],
"reviewText": "If you are a serious violin student on a budget, this edition has it all",
"overall": 5,
"summary": "Perform it with a friend, today!",
"unixReviewTime": 1370476800,
"reviewTime": "06 6, 2013"
}]
to show that into gridview I use the following code (using Json.net library)
JsonString = TextBox1.Text;
dt = (DataTable)JsonConvert.DeserializeObject(JsonString, (typeof(DataTable)));
GridView1.DataSource = dt;
GridView1.DataBind();
the problem is gridview cannot show the data, and it's work if I remove "helpfull" attribute like this one by one :
{
"reviewerID": "A1YS9MDZP93857",
"asin": "0006428320",
"reviewerName": "John Taylor",
"reviewText": "The portfolio is fine except for the fact that the last movement of sonata #6 is missing. What should one expect?",
"overall": 3,
"summary": "Parts missing",
"unixReviewTime": 1394496000,
"reviewTime": "03 11, 2014"}
I don't know code how to remove it , Since i have large json data, i'ts difficult and wasting time to remove it manually. Any idea?
As you are using Json.NET, if you want to remove unwanted properties before deserializing to
DataTable
, you can convert to an intermediate LINQ to JSONJToken
hierarchical representation, then remove properties with unwanted names. After this is done, you can deserialize to your finalDataTable
class withJToken.ToObject<T>
.To parse to a
JToken
, do:Then to remove unwanted properties by name:
Or, to remove all except wanted properties, by name:
Finally, deserialize: