JavaScript / JQuery to retrieve JSON data from the Web API


The output from the Web API is:


And I need to retrieve FNAME from the API using JavaScript/JQuery.

I tried using the code below:

$(document).ready(function () {
           type: 'GET',
           url: 'http://localhost:63456/api/LoginUser',
           data: { q: $(this).val(), format: 'json', pretty: 1 },
           jsonpCallback: 'jsonp',
           dataType: 'jsonp'
       }).then(function (data) {

I am using the below method in the APIController class

public string Userloginvalues()

        List<LoginUser> objModel = new List<LoginUser>();
        OracleConnection con;
        OracleDataAdapter da;
        DataSet ds = new DataSet();
        con = new OracleConnection(ConfigurationManager.ConnectionStrings["ConString"].ToString());
        da = new OracleDataAdapter("select FNAME,LNAME from ACCOUNTS where USERNAME=" + "'" + username + "'" + "  and PASSWORD=" + "'" + password + "'", con);
        foreach (DataRow dr in ds.Tables[0].Rows)
            FNAME_C = dr[0].ToString();
            LNAME_C = dr[1].ToString();

            objModel.Add(new LoginUser{ FNAME = FNAME_C,LNAME = LNAME_C});

        string json = Newtonsoft.Json.JsonConvert.SerializeObject(objModel);
        return json;

Using Jquery you can do like this to get any field you want(using same format of data you are getting).

var $string=$('<string>[{"FNAME":"Prasy","LNAME":"San"}]</string>');
var jsonData=JSON.parse( $string.text());

Working fiddle