Review following code snippet to retrive json data in c#.
String strResult = “”;
strResult += “{‘xproducts’: “;
strResult += “[“;
if (dtable.Rows.Count > 0)
{
for (int i = 0; i < dtable.Rows.Count; i++)
{
strResult += “{ “;
strResult += “‘xid’:'” + dtable.Rows[i][“Id”].ToString() + “‘, “;
strResult += “‘xname’:'” + dtable.Rows[i][“Name”].ToString() + “‘, “;
strResult += “‘xprice’:'” + dtable.Rows[i][“Price”].ToString() + “‘, “;
strResult += “} “;
if (i != dtable.Rows.Count – 1)
{ strResult += “,”; }
}
}
strResult += “]”;
strResult += “}”;
context.Response.ContentType = “text/html”;
context.Response.Write(strResult);
Other Post for javascript: