MyException - 我的异常网
当前位置:我的异常网» ASP.NET » easyui 不判别json

easyui 不判别json

www.MyException.Cn  网友分享于:2013-02-20  浏览:162次
easyui 不识别json
本帖最后由 hyn8477 于 2013-02-05 16:45:01 编辑

<ul id="tt2"></ul>

$(function() {
    $('#tt2').tree({
        animate: true,
        url: 'data/test.ashx',
        onBeforeExpand: function(node, param) {
            $('#tt2').tree('options').url = "data/test.ashx";
        },               
        onClick:function(node){             
        alert(node.id); 
        } 

    })



后台代码

public void ProcessRequest(HttpContext context)
        {
            string str = "[{'id':1,'text':'Folder1','iconCls':'icon-ok','children':[{'id':2,'text':'File1','checked':true},{'id':3,'text':'Folder2','state':'open','children':[{'id':4,'text':'File2','attributes':{'p1':'value1','p2':'value2'},'checked':true,'iconCls':'icon-reload'},{'id':8,'text':'Folder3','state':'closed','children':[{'id':9,'text':'File31'},{'id':10,'text':'File32'}]}]}]},{'text':'Languages','state':'closed','children':[{'id':'j1','text':'Java'},{'id':'j2','text':'C#'}]}]";
            context.Response.ContentType = "text/plain";
            context.Response.Write(str);
            context.Response.End();
        }


但是页面无法显示,求助大神帮忙看一下

------解决方案--------------------
改成下面标准json格式试试,应该jq版本为1.4+怪异模式的json导致没执行success回调,参考:jQuery dataType指定为json的问题



//string str = "[{'id':1,'text':'Folder1','iconCls':'icon-ok','children':[{'id':2,'text':'File1','checked':true},{'id':3,'text':'Folder2','state':'open','children':[{'id':4,'text':'File2','attributes':{'p1':'value1','p2':'value2'},'checked':true,'iconCls':'icon-reload'},{'id':8,'text':'Folder3','state':'closed','children':[{'id':9,'text':'File31'},{'id':10,'text':'File32'}]}]}]},{'text':'Languages','state':'closed','children':[{'id':'j1','text':'Java'},{'id':'j2','text':'C#'}]}]";
//===>
string str ="[{\"id\":1,\"text\":\"Folder1\",\"iconCls\":\"icon-ok\",\"children\":[{\"id\":2,\"text\":\"File1\",\"checked\":true},{\"id\":3,\"text\":\"Folder2\",\"state\":\"open\",\"children\":[{\"id\":4,\"text\":\"File2\",\"attributes\":{\"p1\":\"value1\",\"p2\":\"value2\"},\"checked\":true,\"iconCls\":\"icon-reload\"},{\"id\":8,\"text\":\"Folder3\",\"state\":\"closed\",\"children\":[{\"id\":9,\"text\":\"File31\"},{\"id\":10,\"text\":\"File32\"}]}]}]},{\"text\":\"Languages\",\"state\":\"closed\",\"children\":[{\"id\":\"j1\",\"text\":\"Java\"},{\"id\":\"j2\",\"text\":\"C#\"}]}]";

文章评论

软件开发程序错误异常ExceptionCopyright © 2009-2015 MyException 版权所有