Hi this is a Json data
All I need is to get title, name address
{"success":true,
"data":[
{"id":2123,
"title":"Eyepartners",
"org_id":
{"name":"Eyepartners",
"people_count":1,
"owner_id":2314,
"address":null,
"cc_email":"12345@gmail.com",
"value":1392},
"person_id":
{"name":"Jeff Rinkov","email":[{"label":"work",
"value":"me@someone.com","primary":true}],"phone":[{"label":"work","value":"111-111-231","primary":true}],"value":4087},"value":5000,"currency":"USD","status":"open"}
All I need is to get the title, name, address, cc_email, phone and email
Here's the code I used.
protected void Page_Load(object sender, EventArgs e)
{
StreamReader stRead = new StreamReader(Server.MapPath("~/Test1.json"));
DataTable dataTable = GetDataTableFromJsonString(stRead.ReadToEnd());
gvJsonData1.DataSource = dataTable;
gvJsonData1.DataBind();
}
public DataTable GetDataTableFromJsonString(string json)
{
var jsonLinq = JObject.Parse(json);
// Find the first array using Linq
var srcArray = jsonLinq.Descendants().Where(d => d is JArray).First();
var trgArray = new JArray();
foreach (JObject row in srcArray.Children<JObject>())
{
var cleanRow = new JObject();
foreach (JProperty column in row.Properties())
{
// Only include JValue types
if (column.Value is JValue)
{
cleanRow.Add(column.Name, column.Value);
}
else
{
Response.Write(column.Name);
}
}
trgArray.Add(cleanRow);
}
return JsonConvert.DeserializeObject<DataTable>(trgArray.ToString());
}
protected void gvJsonData1_RowDataBound(object sender, GridViewRowEventArgs e)
{
}
protected void gvJsonData1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
{
}
I get the whole data which I do not need. Of course I got a solution but of client side and right now I need server side help. The source code is here:
http://www.aspforums.net/Threads/136177/Read-Complex-Json-and-convert-Json-string-to-DataTable-using-jQuery-Ajax-in-ASPNet/
Any hint would be really appreciated.