Can you assist me? I have developed a web service that provides a clean string after clicking on the URL:
{
"PersonID": 125,
"Title": "Security Officer",
"Company": "TSA",
"CellNum": "423-915-3224",
"EmergencyPhone": "",
"Email": ""
}
I am looking to extract this string using JSON and retrieve the data. How can I achieve this?
This is my Web Service:
<OperationContract()>
<WebGet(ResponseFormat:=WebMessageFormat.Json, UriTemplate:="/getPersonInfo/?personID={personID}&companyCode={companyCode}", BodyStyle:=WebMessageBodyStyle.Bare)>
Public Function getPersonInfo(ByVal personID As String, ByVal companyCode As String) As Stream
Dim dba As New DBAccess
Dim person As New PersonInfo
Dim m_SelPerson As String = String.Empty
Dim ds As DataSet = dba.GetPersonInfo(personID, companyCode)
If Not ds Is Nothing Then
Dim dr As DataRow = ds.Tables(0).Rows(0)
person = New PersonInfo
person.PersonID = Convert.ToInt32(dr("PersonID"))
person.Company = dr("Company")
person.Title = dr("Title")
person.CellNum = dr("CellNum")
person.EmergencyPhone = dr("EmergencyPhone")
person.Email = dr("Email")
Dim oSerilzer As New System.Web.Script.Serialization.JavaScriptSerializer
m_SelPerson = oSerilzer.Serialize(person)
WebOperationContext.Current.OutgoingResponse.ContentType = "application/json; charset=utf-8"
End If
Return New MemoryStream(Encoding.UTF8.GetBytes(m_SelPerson))
End Function
Here is the JavaScript function:
function getPersonInfo(personID) {
var json = '"http://122.123.1.118/GSWS/Service1.svc/REST/getPersonInfo/?personid=125&companycode=TSA&sensor=false"';
obj = JSON.parse(json);
alert(obj);
}