[Solved] How to get data from C# WebMethod as Dictionary and display response using jquery ajax?


Type “System.String” is not supported for deserialization of an array.

It’s not clear to me why this code is giving this error message. But you may be able to simplify some of this serialization anyway. Since the method is just expecting a string, give it just a string with the expected parameter name as the key. I’m going to assume that AccountType in your JavaScript code is a string:

data: { AccountItem: AccountType }

I don’t know how to return Dictionary<> respose

Same way you’d return anything. So, for example, if you want to return a Dictionary<int, ReportDetail> you could do this:

[WebMethod]
public static Dictionary<int, ReportDetail> GetReportDetail(string AccoutItem)
{
    return new Dictionary<int, ReportDetail>();
}

As for how you would populate that object with actual data (instead of just returning an empty dictionary), that’s entirely up to you.

and process using jquery over that

When you return actual data, use your browser’s debugging tools to examine the structure of the JSON response. It’s really just an array of objects. You can loop over it, examine the properties of the objects, etc. just like any other objects.

success: function (data) {
    for (var i = 0; i < data.length; i++) {
        // do something with data[i]
    }
}

2

solved How to get data from C# WebMethod as Dictionary<> and display response using jquery ajax?