[英]result shows System.String[]
On my GetBusiness.aspx page i have create a test list 在我的GetBusiness.aspx页面上,我创建了一个测试列表
List<string> l = new List<string>();
l.Add("one");
l.Add("two");
l.Add("three");
l.Add("four");
l.Add("five");
// B.
string[] s = l.ToArray();
Response.Write(s);
No on my second page(default aspx page) I have some jQuery to load this array and show the results: 在第二页(默认aspx页)上没有,我有一些jQuery可以加载此数组并显示结果:
$.get('GetBusiness.aspx', function (returndata) {
// for each address in returndata
alert(returndata);
but the result is : System.String[] If I iterate , he iterate the string "System.String[]" 但是结果是:System.String []如果我进行迭代,他将迭代字符串“ System.String []”
$.each(returndata, function (index, value) {
alert(index + ': ' + value);
};
How can I show the results from the string array? 如何显示字符串数组的结果?
Change Response.Write(s)
to : 将
Response.Write(s)
更改为:
JavaScriptSerializer objSerializer = new JavaScriptSerializer();
Response.Write(objSerializer.Serialize(s));
Reference: JavaScriptSerializer 参考: JavaScriptSerializer
In your GetBusiness page, you are outputting the .ToString()
property of the array, which is "System.String[]". 在GetBusiness页面中,您正在输出数组的
.ToString()
属性,即“ System.String []”。 You need to iterate the list and output each element separatly in some usable format, like JSON and then parse appropriately. 您需要迭代列表并以某种可用格式(例如JSON)分别输出每个元素,然后进行适当的解析。
Example (untested): 示例(未试用):
string reponse = "";
response += "{ \"Output\":[";
for(int i = 0; i < s.Length; i++) {
response += s[i];
if (i < s.Length - 1) response += ", "
}
response += "] }";
Response.Write(response);
List<string> l = new List<string>();
l.Add("one");
l.Add("two");
l.Add("three");
l.Add("four");
l.Add("five");
// B.
string[] s = l.ToArray();
Response.Write(string.Join(",", s));
javascript: javascript:
$.get('GetBusiness.aspx', function(returndata) {
var arr = returndata.split(',');
$.each(arr, function(index, value) {
alert(index + ': ' + value);
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.