Link to home
Start Free TrialLog in
Avatar of RTSol
RTSol

asked on

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
Avatar of leakim971
leakim971
Flag of Guadeloupe image

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

and not :
url: '/api/users/' + username + '/' + password,
Avatar of RTSol
RTSol

ASKER

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
Look at your JSON, you probably need this:

var obj = $.parseJSON(Data);
alert(obj.Data.FullName);
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...
ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of RTSol

ASKER

Thanks a lot - that is what I needed.