由于项目需要,所以想了解Jquery与Json
具体的是想知道一下如何使用Jquery解析Json的数据。
哪位能提供个例子或者源码什么的,感谢。

解决方案 »

  1.   

    这个可以百度一下。主要是用$.each方法。。参考
      

  2.   

        <script type="text/javascript">
            $(document).ready(function(){
                $.ajax({
                    url:"Handler.ashx",
                    type:"get",
                    dataType:"json",
                    data:null,
                    success:function(result){
                        $.each(result,function(i){
                            alert(result[i].ID+"==="+result[i].Name);
                        })
                    }
                })
            })
        </script>
        public void ProcessRequest (HttpContext context) {
            context.Response.ContentType = "text/plain";
            System.Collections.Generic.List<User> list = new System.Collections.Generic.List<User>();
            string[] name = { "床", "上", "等", "你" };
            for (int i = 0; i < name.Length; i++)
            {
                User user = new User();
                user.ID = i + 1;
                user.Name = name[i];
                list.Add(user);
            }
            System.Web.Script.Serialization.JavaScriptSerializer json = new System.Web.Script.Serialization.JavaScriptSerializer();
            context.Response.Write(json.Serialize(list));
            context.Response.End();
        }
        public class User
        {
            private int iD;
            public int ID
            {
                get { return iD; }
                set { iD = value; }
            }
            private string name;
            public string Name
            {
                get { return name; }
                set { name = value; }
            }
        }
      

  3.   

    jQuery.getJSON(url,[data],[callback]),通过 HTTP GET 请求载入 JSON 数据。
    参数:
          url (String) : 发送请求地址。
          data (Map) : (可选)待发送 Key/value 参数。
          callback (Function) : (可选)载入成功时回调函数。例子:test.htm<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head>
        <title></title>
        <script type="text/javascript" src="jquery-1.4.2.min.js"></script>
        <script type="text/javascript">
        function getData(){
           $("#list").html("");
           $.getJSON("Handler1.ashx",
                   {name:"test",age:20},
                    function(data){
                   $.each(data, function(i) {
                   $("#list").append("<li>姓名:" + data[i].name + "&nbsp;性别:" + data[i].sex + "&nbsp; 年龄:" + data[i].age + "</li>")
                          })
                    })
         }
        </script>
    </head>
    <body>
    <input id="Button1" type="button" value="获取数据" onclick="getData()" />
       <ul id="list"></ul>
    </body>
    </html>
      

  4.   

    http://www.cnblogs.com/chenping-987123/archive/2011/02/14/1954640.html
    其实这是2个不同的内容,可以分开来单独的进行了解。
      

  5.   

    学习  最近在看jquery ajax
      

  6.   

    上面的例子好多都是Ajax
    但事实上Json和Ajax几乎没有任何关系,Json是现在比较认同的一种基于JS的轻量级的数据交换格式(JS对象)。
    对象.属性而JQuery是一个轻量级的JS框架(函数库),可以提高开发效率,省时省力还兼顾兼容性
      

  7.   

    传送师
    你下个Jquery手册看看就知道了。
      

  8.   


    还没解决?说了就是Juqery  each方法。下个帮助文档。。理解一下这个方法才是最得要的给你那么多代码也没用
      

  9.   


    我的json字符串 
    {"info":[{"id":"344","name":"EC7-RV"},{"id":"347","name":"EC718"},{"id":"610","name":"EC7 CVT"}]}
    jquery 解析 
     $.each(data.info, function(i,item) {
      if(i!=0){ 
      temp += "<option value="+item.id+">"+item.name+"</option>";
      }
    });