1
Reply

Webservices with JSON response format

Rahul Lakshakar

Rahul Lakshakar

Sep 8 2017 6:47 AM
157
Hello,
 
I am creating web services in my asp.net project and getting result in the format of JSON. First webmethod is working is fine but in second one i am getting no value in JSON array.
 
Can any one suggest me something?
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function GetStudentJSON(sname As String) As String
Dim sqlStr As String = "Select * from vw_Student where SName like '%" & sname & "%' "
Dim myReader As SqlDataReader = ExecuteQuery_ExecuteReader(sqlStr)
Dim student As New List(Of Student)()
While myReader.Read
student.Add(New Student() With { _
.SID = myReader("SID"), _
.RegNo = myReader("RegNo"), _
.SName = myReader("SName")})
End While
myReader.Close()
Return New JavaScriptSerializer().Serialize(student)
End Function
 
 
<WebMethod()> _
<ScriptMethod(ResponseFormat:=ResponseFormat.Json, UseHttpGet:=True)> _
Public Function GetParentJSON(SID As Integer) As String
Dim sqlStr As String = "Select * from ParentLogins where SID = '" & SID & "' "
Dim myReader As SqlDataReader = ExecuteQuery_ExecuteReader(sqlStr)
Dim student As New List(Of Student)()
While myReader.Read
student.Add(New Student() With { _
.SID = myReader("SID"), _
.RegNo = myReader("RegNo"), _
.SName = myReader("SName")})
End While
myReader.Close()
Return New JavaScriptSerializer().Serialize(student)
 
 
i am using a student class in this. 
 

Answers (1)