Hi ManjuNaga,
Check this example. Now please take its reference and correct your code.
HTML
<div>
<span class="input-group-btn">
<button class="btn btn-default" type="button" id="employee">
Get Record</button>
</span>
<table id="content">
<thead>
<tr>
<th>
Id
</th>
<th>
question
</th>
<th>
course
</th>
<th>
AnswerId
</th>
<th>
Ans
</th>
<th>
status
</th>
</tr>
</thead>
<tbody id="emp">
</tbody>
</table>
</div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script type="text/javascript">
$(function () {
$("#employee").on("click", function () {
$.ajax({
url: 'CS.aspx/fecthcourse',
type: "POST",
dataType: "json",
contentType: "application/json; charset=utf-8",
success: function (data) {
var json = JSON.parse(data.d);
$(json).each(function (index, item) {
var questionId = json[index].id;
var question = json[index].question;
var course = json[index].course;
for (var option = 0; option < json[index].answerEntities.length; option++) {
var ans = json[index].answerEntities[option].ans;
var ansId = json[index].answerEntities[option].id;
var ansStatus = json[index].answerEntities[option].status;
$('tbody#emp').append(
'<tr><td>'
+ questionId
+ '</td><td>'
+ question
+ '</td><td>'
+ course
+ '</td><td>'
+ ansId
+ '</td><td>'
+ ans
+ '</td><td>'
+ ansStatus
+ '</td></tr>')
}
});
},
error: function (data) { alert(data.responseText); }
});
});
});
</script>
Code
C#
[System.Web.Services.WebMethod]
public static string fecthcourse()
{
return System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("~/JsonData.json"));
}
VB.Net
<System.Web.Services.WebMethod>
Public Shared Function fecthcourse() As String
Return System.IO.File.ReadAllText(HttpContext.Current.Server.MapPath("~/JsonData.json"))
End Function
JsonData.json
[
{
"id": 1,
"question": "What is JDBC.?",
"course": "J2EE",
"answerEntities": [
{
"id": 1,
"ans": "B",
"status": false
},
{
"id": 2,
"ans": "D",
"status": false
},
{
"id": 3,
"ans": "C",
"status": false
},
{
"id": 4,
"ans": "J",
"status": true
}
]
},
{
"id": 2,
"question": "What is java..?",
"course": "Java",
"answerEntities": [
{
"id": 5,
"ans": "Easy to understand",
"status": false
},
{
"id": 6,
"ans": "Platform independent",
"status": false
},
{
"id": 7,
"ans": "Rebust",
"status": true
},
{
"id": 8,
"ans": "Secure",
"status": false
}
]
}
]
Screenshot
