[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 386
  • Last Modified:

Parsing json

Hi,

I have a service call in my application which returns jsaon data. The call is like so:

            $.ajax({
                type: "GET",
                dataType: "json",
                url: 'http://rest.smartdoc.se/api/users/' + username + '/' + password,
                success: function (Data) {
                    var obj = $.parseJSON(Data);
                    alert(obj.FullName);
                }

            });

Open in new window


The service returns this:

{"Data":[{"FullName":"Doesn't exist","username":"sdf","password":"sdf"}],"Errors":null}

Open in new window


There obviously is something wrong because it is not working. Please help me.

Best regards
RTSol
0
RTSol
Asked:
RTSol
1 Solution
 
leakim971PluritechnicianCommented:
why :
url: 'http://rest.smartdoc.se/api/users/' + username + '/' + password,

and not :
url: '/api/users/' + username + '/' + password,
0
 
RTSolAuthor Commented:
Hi,

The application is running on a smartphone. I need to provide the complete url to the service which is running on a web server. The call to the service works fine and it returns the desired json. My problem is just to parse it.

-RTSol
0
 
Chris StanyonCommented:
Look at your JSON, you probably need this:

var obj = $.parseJSON(Data);
alert(obj.Data.FullName);
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Alexandre SimõesManager / Technology SpecialistCommented:
Well... I looked at your code and really bad is this line:

'http://rest.smartdoc.se/api/users/' + username + '/' + password

You're passing username and password in clear text and not even https?
And I hope you're not doing this for each request...
0
 
Chris StanyonCommented:
Actually, no - you need this:

success: function (Data) {
    var person = Data.Data[0]; //grab the first person from the Data array
    alert(person.FullName);
}

Open in new window

The Data returned contains a Data key, holding an array or people. If you are likely to be passing back more than one person then you'll need to loop through Data.Data
0
 
RTSolAuthor Commented:
Thanks a lot - that is what I needed.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now