首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

树形结构的json字符串,怎么变成json对象

2013-07-20 
树形结构的json字符串,如何变成json对象?{status:succeed,msg:成功,data:[{id:1,name:根目录,

树形结构的json字符串,如何变成json对象?


{status:"succeed",msg:"成功",
data:
[
{
"id":"1","name":"根目录","totalCount":12000,
child:
[
{
"id":"137","name":"服饰","totalCount":5000, 
child:
[
{
"id":"140","name":"男装","totalCount":5000, 
child:
[
{
"id":"141","name":"裤子","totalCount":5000
}
]
}
]
}
]
}
]
}


树形结构的json字符串,如何变成json对象?

1、数据如上。
2、不能使用js的eval('('+data+')')。
3、上面是一串字符串,是string类型的,为了方便大家看,加了空格和tab,大家可以当作类似string str='上面的字符串',这个字符串没有空格和tab。
4、要把这串长长的string类型的字符串变成json对象。


[解决办法]
最底层的对象为什么没有child?
[解决办法]
用dynamic去做 如果你是动态的话,
http://blog.csdn.net/educast/article/details/7328106
或者自己构建类去反序列化
[解决办法]
LZ 参考下  这是我的TREE的JSON

  string value = "[{"id":0,"text":"自定义组视图"},{"id":-1,"text":"所有测点","iconCls":"ico_blank","children":";//[{"id":2,"text":"测点1"},{"id":3,"text":"测点2"},{"id":4,"text":"测点3"}]}]";
                    string children = "[";
                    for (int a = 0; a < spots.Rows.Count; a++)
                    {
                        if (a != spots.Rows.Count - 1)
                        {
                            children += "{"id":" + spots.Rows[a]["id"].ToString() + ","text":"" + spots.Rows[a]["name"] + ""},";


                        }
                        else
                        {
                            children += "{"id":" + spots.Rows[a]["id"].ToString() + ","text":"" + spots.Rows[a]["name"] + ""}";
                        }
                    }
                    children += "]";
                    value += children;
                    value += "}]";
                    context.Response.Clear();
                    context.Response.ContentEncoding = Encoding.UTF8;
                    context.Response.ContentType = "application/json";
                    context.Response.Write(value);
                    context.Response.Flush();
                    context.Response.End();

热点排行