0

I need your help: I created a web service that returning me a clean string after clicking on the url:

{
    "PersonID": 125,
    "Title": "Security Officer",
    "Company": "TSA",
    "CellNum": "423-915-3224",
    "EmergencyPhone": "",
    "Email": ""
}

How can I extract that string using JSON and get the data??

My WebService:

 <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

JS 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);
    }
6

1 Answer 1

0
<http>
<script src='http://code.jquery.com/jquery-1.11.1.min.js'></script>
<body>

<script>
    var url = "http://122.123.1.118/GSWS/Service1.svc/REST/getPersonInfo/?personid=125&companycode=TSA&sensor=false";
    $.getJSON( url, function( data ) {
        alert(data.PersonID);
    });
</script>

</body>
</html>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.