Parsing returned List<KeyValuePair<String,String>> javascript from AJAX call

HI,

I return a List<KeyValuePair<String,String>> form a C# webmethod ajax call.

    runAjax('/Public/AdminServices.asmx/GetFonts', null)
    .done(function (fonts) {
        alert(fonts.d); //alerts Object object Object object

        var html = "<ul class='fontList'>";

        for(var i=0; i<fonts.d.length; i++)
        {
            //both alerting undefined??
            alert(fonts.d[i][0].toString() + fonts.d[i][1].toString());
            html += "<li data-url='" + fonts.d[i][0] + "'>" + fonts.d[i][1] + "</li>";
        }

Open in new window


my webmethod works as follows ( and form debugging is returning 2 lines of values);

HttpWebRequest request = WebRequest.Create(fonts_path) as HttpWebRequest;
        request.Accept = "*/*";
        WebResponse response = request.GetResponse();
        Regex regex = new Regex("(?i)<a href=\"(?<url>.*?)\">(?<text>.*?)</a>");
        List<KeyValuePair<String, String>> files = new List<KeyValuePair<String, String>>();

        using (var reader = new StreamReader(response.GetResponseStream()))
        {
            string result = reader.ReadToEnd();
            MatchCollection matches = regex.Matches(result);

            if (matches.Count == 0)
            {
                Global.log.Info("ERROR: Trying to list fonts from resource directory");
                return null;
            }

            foreach (Match match in matches)
            {
                if (!match.Success) { continue; }

                if (match.Groups["url"].ToString() != "/")
                {
                    Global.log.Info("Debug: MATCH :" + match.Groups["url"].ToString() + ":" +  match.Groups["text"].ToString() + ":");
                    files.Add(new KeyValuePair<String, String>(match.Groups["url"].ToString(),match.Groups["text"].ToString()));
                }
            }
        }

        return files;

Open in new window


any ideas how I can get the two values from the list on the clientside return?
flynnyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mccarlIT Business Systems Analyst / Software DeveloperCommented:
As mentioned in your other question, try this...
    runAjax('/Public/AdminServices.asmx/GetFonts', null)
    .done(function (fonts) {
        alert(fonts.d); //alerts Object object Object object

        var html = "<ul class='fontList'>";

        for(var i=0; i<fonts.d.length; i++)
        {
            //both alerting undefined??
            alert(fonts.d[i]['Key'].toString() + fonts.d[i]['Value'].toString());
            html += "<li data-url='" + fonts.d[i]['Key'] + "'>" + fonts.d[i]['Value'] + "</li>";
        }

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
flynnyAuthor Commented:
thanks as it was off topic from the previous question i opened a new one. Sorry i didnt realised you replied there!
0
mccarlIT Business Systems Analyst / Software DeveloperCommented:
You're welcome!

No worries. I think that I posted in the other question after you had opened this question (which is probably the right thing to do anyway). I just hadn't seen this new question before I posted the reply in the other one.

Oh, BTW, another syntax you could use is.... fonts.d[ i].Key and fonts.d[ i].Value    The .dot notation or the array [subscript] notation should work the same.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
jQuery

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.