Knockout problem, cannot use the "in" operator to search for "length"

I get the following error in my web application using Knockout.js

Cannot use 'in' operator to search for 'length'

My code is:

$(document).ready(function () {
        AjaxRequest();
    });

    function AjaxRequest() {
        $.post("../../Api/DisabilitiesHandler.ashx?method=get", function (data) {
            var viewModel = {
                disabilities: ko.observableArray(data)
            };

            ko.applyBindings( viewModel, document.body);
        });
    }

<table>
    <tbody data-bind="template: { name: 'disabilitiesRowTemplate', foreach: disabilities }"></tbody>
</table>

<script type="text/html" id="disabilitiesRowTemplate">
    <tr>
        <td>Name:
            <input data-bind="value: Name" /></td>
        <td>
           Active <input type="checkbox" data-bind="checked: Active" /></td>
    </tr>
</script>

And this is my model

public class Disabilities
{
    public int Id { get; set; }
    public string Name { get; set; }
    public bool Active { get; set; }
}

And this is the web service code

context.Response.ContentType = "application/JSON";
DbsaDal.Entities.DBSAEntities db = new DbsaDal.Entities.DBSAEntities();
List<DbsaDal.Model.Disabilities> disabilities = DbsaDal.Entities.Disabilities.Get(db);
context.Response.Write(new JavaScriptSerializer().Serialize(disabilities));

Any suggestions on what to do? I searched everywhere on the Internet and found nothing useful

Update 1:

Uncaught TypeError: Cannot use 'in' operator to search for 'length' in [{"Id":1,"Name":"Blind","Active":false},{"Id":2,"Name":"Mute","Active":true}] Knockout.js:92
+5
source share
1 answer

I found my problem:

disabilities: ko.observableArray(data)

This piece of code should have been

disabilities: ko.observableArray(ko.utils.parseJson(data))
+5
source

All Articles