Extracting information from a string with JSON in Javascript

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

Answer №1

<https>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.min.js'></script>
<body>

<script>
    var url = "https://example.com/api/getUserInfo/?id=123&token=abc123&format=json";
    $.getJSON( url, function( data ) {
        alert(data.UserID);
    });
</script>

</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

When the anchor tag is clicked, I'm displaying the DIV for Customer Testimonials, however, the expansion of its height is not

One way to display customer testimonials is by using flexslider to create a horizontal scroll. The testimonials are hidden and only shown when the "view all testimonials" link is clicked, which can be seen in this JSFiddle example: Working : Demo JQuery ...

Is it possible to integrate SignalR with all types of databases?

Looking to incorporate push technology into my application for real-time data updates. Currently using ASP.NET MVC with IBM Informix as the backend database. Wondering if SignalR can be integrated with Informix and if it has any specific database depende ...

Issues arise when attempting to smoothly scroll to an anchor point in a webpage

While working on my website, I have encountered a challenge. The issue arises when dealing with multiple div items. Upon scrolling slightly, the entire page focuses on the div with a height of 100vh, which works perfectly fine. However, my attempts to ...

Why does the width of my image appear differently on an iPhone compared to other devices?

I recently encountered an issue with the responsiveness of an image on my website. While it displayed correctly on Android and desktop devices, the image appeared distorted on iPhones as if the CSS width attribute was not applied properly. This problem spe ...

Creating a Regular Expression that excludes all white spaces, including those at the start or end of the string

I attempted to implement this solution, however, I am encountering some issues: Click here to see the demo <form name="myform1"> Valid? {{ myform1.$valid }} <input type="text" name="username1" ng-model="username1" ng-pattern="/^\S.*?&bso ...

Trouble with controlling the speed of ajax requests while using vue-multiselect and lodash

I am working on a Vue application that includes a vue-multiselect component. My goal is to load the multiselect options via ajax. To achieve this, I am using lodash.throttle to limit the frequency of ajax requests as the user types in the search criteria ...

Creating an npm module using an external JavaScript API script

I am currently in the process of creating an npm package using code from this repository. In my possession is the "minified" js file called http_www.webglearth.com_v2_api.js, which is automatically downloaded by IntelliJ when the <script src=""> tag ...

What is the process of creating a MaterialUI checkbox named "Badge"?

Badge API at https://material-ui.com/api/badge/ includes a prop called component that accepts either a string for a DOM element or a component. In my code: <Badge color="primary" classes={{ badge: classes.badge }} component="checkbox"> <Avatar ...

Extract the HTML table from Gmail and transfer it to Google Sheets with the help of Google Apps Script

Just dipping my toes into google apps script. On my to-do list is creating a script that can extract data from a table in Gmail and transfer it to Google Sheets. Here's an example of what the email body looks like: CONFIRMATION CODE GUEST&apo ...

What is the process for converting several files into a base64 string?

I have a component set up like this: <input type="file" multiple @change="toBase64Handler($event)"> <script> data() { return { files: [], } }, methods: { tobase64Handler(event) { // implementation } } </script> I w ...

Elegant switch in jQuery

I am trying to use jQuery to create an animated toggle button. The toggle function is working correctly, but I am having trouble adjusting the speed and smoothness of the animation. After researching different methods and attempting to modify the values i ...

My goal is to transfer information from the client-side to the server-side upon the user disconnecting from a socket.io connection using Node.js

Is there a way to transmit data from the client side to the server side when a user disconnects from a socket.io connection in Node.js? I attempted creating a new event and calling it within the 'disconnect' event, but it seems impossible since t ...

Preventing Users from Accessing a PHP Page: Best Practices

I'm currently focusing on a problem that involves restricting a user from opening a PHP page. The following is my JavaScript code: <script> $('input[id=f1email1]').on('blur', function(){ var k = $('inp ...

Angular Binding issue - Unable to bind to 'ngModel' as it is not recognized as a valid property of 'input' element, despite the property being present

I have developed a component class like the one below and I am attempting to link the class fields to the template, but encountered the following error: ERROR in src/app/admin/projects/projects.component.html: 41:34 - error NG8002: Can't bind to &ap ...

Arranging unrelated divs in alignment

http://codepen.io/anon/pen/Gxbfu <-- Here is the specific portion of the website that needs alignment. My goal is to have Onyx Design perfectly aligned with the right side of the navbar, or to have the navbar extend up to the end of "Onyx Design". The ...

Converting JSON data from the OpenWeatherMap API into a string format

I am looking to display a message on the screen that reads something like "Dublin is experiencing clouds today with a temperature of 15". How can I extract the values for weather.main and temperature from this JSON data and incorporate them into my string ...

Create a Python program that downloads JSON data and then either saves it as a CSV file or converts it

I'm struggling to download data in JSON format and convert it into a CSV file. Specifically, I need company overview data from alphavantage () Here's the script I've been using to download the data: import requests import pathlib solditems ...

Vue encounters an issue when trying to access a specific field within an array of objects

Consider the following data structure: rules:[ 0:{ subrule1:'', subrule2:'', subrule3:'' }, 1:{ subrule1:'', subrule2:'', subrule3:'' } ...

My mongoose sort function doesn't seem to be functioning properly. What could be the issue?

Hey there! I've got a simple API up and running on Node.js, using MongoDB as my database with Mongoose for querying. The issue I'm facing is related to sorting data using the mongoose 'sort' method. Instead of behaving as expected, it s ...

Ways to send data to nested elements when implementing secure routes?

I am currently working on a project to develop a 'Train Ticket Reservation System' using ReactJS. In order to access the services, users must login, so I have implemented protected routes to render certain components. Instead of relying on the de ...