zoukankan      html  css  js  c++  java
  • JSON in JavaScript Asp.net

    首先官方网站  http://www.json.org/js.html

    下载 json2.js 到Github 中下载 https://github.com/douglascrockford/JSON-js

    后台定义并生成json 后返回前台


    在这里我们在后台做一个简单的返回(在AbnormalCustomerList.ashx.cs中)

    string stbList = "{"Rows":[";
                stbList = stbList + "{ "id": 1, "name": "林三", "sex": "男", "birthday": "1989/01/12"},";
                stbList = stbList + "{ "id": 2, "name": "张武", "sex": "男", "birthday": "1986/11/24"}";
                stbList = stbList +"],";
                stbList = stbList + ""Count":[{"total":2}]";//用来记录一共返回了几条数据记录
                stbList = stbList +"}";

     context.Response.Write(stbList.ToString());

    前台引用

    var varReceiver = JSON.parse(e.result);
             //alert(varReceiver.Rows[0].name)
             for (var i = 0; i < varReceiver.Count[0].total; i++)
             {
                 alert(varReceiver.Rows[i].name)
             }
            

    在alert的时候就会依次Popup得到 林三 张武

    另外:JSON.parse()和JSON.stringify()的用法

    http://blog.csdn.net/wangxiaohu__/article/details/7254598

    上述做法,对stbList的生成有很严格的要求,如果有一个字符拼凑出错都会导致前台引用的失败。

  • 相关阅读:
    单例模式和配置admin
    ORM单表查询,跨表查询,分组查询
    进程同步控制 Lock Semaphore Event
    创建进程和多进程 process join p.daemon terminate
    并发编程基础
    远程执行模块和黏包 socketserve hamc模块验证合法性
    网络编程之Socket
    网络基础
    del new item hash 单例模式
    面向对象进阶
  • 原文地址:https://www.cnblogs.com/xp1056/p/5287187.html
Copyright © 2011-2022 走看看