我正在字符串中从ashx句柄中获取json对象到我的js,代码如下
<script type="text/javascript">
var path = 'Handler.ashx';
$.ajax({
url: path,
dataType: 'json',
}).success(function (data) {
$('#content').html(JSON.stringify(data.a))
});
</script>
和装卸机的代码
using System;
using System.Data;
using System.Web;
using System.Linq;
using System.Collections;
using Newtonsoft.Json;
public class Handler : IHttpHandler {
public string ProcessRequest (HttpContext context) {
string a = "hello world";
return JsonConvert.SerializeObject(a);
}
public bool IsReusable {
get {
return false;
}
}
我无法从以下代码中获取任何输出plz更正代码thnk u
在字符串上使用JsonConvert.SerializeObject
只会返回字符串,因为实际上没有什么要序列化的。
因此,JSON.stringify(data.a)
将不起作用,因为data
只是字符串"hello-world",它没有名为a
的属性——data.a
将是undefined
。