【发布时间】:2015-01-18 12:10:35
【问题描述】:
我用 asp.net 和 jquery.in 编写了一个项目,我有一部分网页:
<div id="lookup">
<div class="other">
<div class="st"></div>
<ul class="videos"></ul>
<ul class="items"></ul>
在网络服务中,我编写此代码来获取搜索关键字并在视频和产品集合中搜索并将其返回到网页。网络服务的一部分是:
public string GetSearchResult(string keyword, string urlCode)
{
string test = [sample code];
string test2 = [sample code2];
StringBuilder sb = new StringBuilder(test);
StringBuilder sb2 = new StringBuilder(test2);
return @"[
{
""Key"": ""video"",
""Value"": {
""m_MaxCapacity"": " + sb.MaxCapacity + @",
""Capacity"": " + sb.Capacity + @",
""m_StringValue"": """ + test + @""",
""m_currentThread"": 0
}
},
{
""Key"": ""product"",
""Value"": {
""m_MaxCapacity"": " + sb2.MaxCapacity + @",
""Capacity"": " + sb2.Capacity + @",
""m_StringValue"": """ + test2 + @""",
""m_currentThread"": 0
}
}]";
}
在 jquery 中,部分代码是:
function lookUp() {
n = $("#SearchBox").val().trim(),
r = "All";
n.length >= 2 ? ($.ajax({
url: ServiceUrl + "SearchService.asmx/GetSearchResult",
data: '{keyword: "' + n + '",urlCode:"' + r + '" }',
type: "POST",
contentType: "application/json; charset=utf-8",
timeout: 15000,
processData: !1,
success: function (o) {
o != null && (r == "All" ? (f.show(), u.show().html(o[2].Value.m_StringValue), .........
此代码必须从网络服务中获取视频类别或产品类别的搜索结果,并使用示例代码或示例代码2 在网页中填写视频或项目 ul。 此代码不起作用。我想确定每个 m_StringValue。我知道从网络服务返回的不应该是文本,我想成为:
[{"Key":"video","Value": {"m_MaxCapacity":2147483647,"Capacity":64,"m_StringValue":"sample code","m_currentThread":0}},
{"Key":"product","Value": {"m_MaxCapacity":2147483647,"Capacity":55,"m_StringValue":"sample code 2","m_currentThread":0}}]
但我不知道如何更改网络服务。
【问题讨论】:
-
谢谢,但你能解释更多吗?你的链接不喜欢我的问题。我想定义键、值、容量、最大容量。
-
这取决于你想在哪里确定它,在 Jacascript 中还是在哪里?
-
我想在 asp.net 网络服务中确定 maxcapacity,capacity,...。
-
为什么要以这种复杂的格式返回 JSON?为什么不用
{"video":"sample code","product":"sample code 2"}表示单个结果或[{"video":"sample code","product":"sample code 2"}]表示多个结果?还有,你是问我们怎么用c#写webservice代码,还是用javascript写jquery代码?
标签: c# asp.net json web-services