1

I'm playing around with the new mvc web api and knockout.js and came across a scenario where $.getJSON is returning a deserialized object vs a json string. Not really a problem but I'm just curious as to why it's occurring. Can anyone explain? Thanks

 //Web Api call

 public UserViewModel GetNewUser()
 {
        var userViewModel = new UserViewModel()
        {
             Id = Guid.NewGuid(),
             Name = "Test"
        };

        return userViewModel;
}

//client code
$.getJSON('/api/User/GetNewUser', function (result) {
    //var viewModel = ko.mapping.fromJS(result);
    //result is already parsed to ojbect
}



enter code here

1 Answer 1

1

That is the documented "magic" behind jQuery.getJSON:

The success callback is passed the returned data, which is typically a JavaScript object or array as defined by the JSON structure and [which is] parsed using the $.parseJSON() method. It is also passed the text status of the response.

(Where does "knockout.js" fit in this?)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.