flynny
asked on
Parsing returned List<KeyValuePair<String,String>> javascript from AJAX call
HI,
I return a List<KeyValuePair<String,S tring>> form a C# webmethod ajax call.
my webmethod works as follows ( and form debugging is returning 2 lines of values);
any ideas how I can get the two values from the list on the clientside return?
I return a List<KeyValuePair<String,S
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>";
}
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;
any ideas how I can get the two values from the list on the clientside return?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
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.
ASKER