views:

35

answers:

1

I want to return an array of javascript objects from my asp.net asmx file. ie.

variable = [
    {
        *value1*: 'value1',
        *value2*: 'value2',
        ...,
    },
    {
    .
    .
    }
];

I seem have been having trouble reaching this. I'd put this into code but I've been hacking away at it so much it'd probably do more harm than good in having this answered.

Basically I am using a web service to find names as people type the name. I'd use a regular text file or something but its a huge database that's always changing - and don't worry I've indexed the names so searching can be a little snappier - but I would really prefer to stick with this method and just figure out how to get usable JSON back to javascript. I've seen a few that sort of attempt to describe how one would approach this but I honestly think microsofts articles are damn near unreadable.

Thanks in advance for assistance.

EDIT: I'm using the $.ajax() function from jQuery - I've had it working but it seems like I was doing it in bad practice not returning and using actual JSON. Previously I'd take a string back and insert it into html to use the variable it set - very roundabout.

A: 

I just figured I'd answer because I hate when people ask a question, discover the answer, then don't share.

I went here http://weblogs.asp.net/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx which convinced me to convert my site from vb to C# because I actually understand why C# works and I hated vb from the start - I just figured it'd maybe get better and be worth learning a little of. literally all I did was implement that tiny little static class and bam it works how I like it.

jphenow
Thanks, similar to what I did here: http://stackoverflow.com/questions/2225781/asp-net-web-method-that-accepts-a-listcustomobject-is-failing-with-web-service/2268178#2268178
Mark Schultheiss