I have looked for a solution , but nothing that fits my needs was found on the site, so here goes:

I have a Controller that returns a Json:

  return Json(new { Item = searchModule});

searchModule is a list of Profiles:

{ "Item":[{"ProfileID":4854,"NickName":"Johnny","users":null,"FirstName":"John","LastName":"Doe"}]}

In JavaScript we have:

  $.ajax({
         type: "POST",
         url: action/controller,
         data: "{queryString:'" + searchVal + "'}",
         contentType: "application/json; charset=utf-8",
         dataType: "json",
         success: function (data) {
         alert(data.Item)
         }
     })

That returns an object. How can I obtain: Firstname,LastName and NickName ???

Additional answer: If I write the code like below:

var request = $.ajax({
             type: "POST",
             url: action/controller,
             data: "{queryString:'" + searchVal + "'}",
             contentType: "application/json; charset=utf-8",
             dataType: "json",
             success: function (data) {
}
         }).responseText
var obj = json.Parse(request)


, request is null.

link|improve this question

60% accept rate
1  
feedback

1 Answer

up vote 1 down vote accepted

since they're objects structured according to the JSON, you should be able to just access the properties like so: data.Item[0].Firstname. You may or may not need to use jQuery.parseJSON to get to this step - calling that is trivial.

link|improve this answer
Thanks.Works fine.Tried it 2 hours ago, apparently my process needed to be killed . data.Item[0].Firstname worked fine . – Noobsyke Apr 3 at 10:41
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.