Parsing json

Posted on 2013-11-05
Last Modified: 2013-11-05

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

                type: "GET",
                dataType: "json",
                url: '' + username + '/' + password,
                success: function (Data) {
                    var obj = $.parseJSON(Data);


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
Question by:RTSol
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 82

Expert Comment

ID: 39623947
why :
url: '' + username + '/' + password,

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

Author Comment

ID: 39624012

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.

LVL 43

Expert Comment

by:Chris Stanyon
ID: 39624016
Look at your JSON, you probably need this:

var obj = $.parseJSON(Data);
Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

LVL 30

Expert Comment

by:Alexandre Simões
ID: 39624025
Well... I looked at your code and really bad is this line:

'' + 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...
LVL 43

Accepted Solution

Chris Stanyon earned 500 total points
ID: 39624027
Actually, no - you need this:

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

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

Author Closing Comment

ID: 39624042
Thanks a lot - that is what I needed.

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Confluence of Individual Knowledge and the Collective Intelligence At this writing (summer 2013) the term API ( has made its way into the popular lexicon of the English language.  A few years ago, …
In this article you'll learn how to use Ajax calls within your CodeIgniter application. To explain this, I'll illustrate how to implement a simple contact form to allow visitors to send you an email through your web site.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question