zoukankan      html  css  js  c++  java
  • json具体解释

    <span style="font-size:12px;">function testJson() {
    
    	var jsonData = {
    		"firstName" : "John",
    		"lastName" : "Doe",
    		"age" : 23
    	};
    
    	var employees = {
    		"accounting" : [// accounting is an array in employees.
    		{
    			"firstName" : "John", // First element
    			"lastName" : "Doe",
    			"age" : 23
    		}, {
    			"firstName" : "Mary", // Second Element
    			"lastName" : "Smith",
    			"age" : 32
    		}], // End "accounting" array.
    		"sales" : [// Sales is another array in employees.
    		{
    			"firstName" : "Sally", // First Element
    			"lastName" : "Green",
    			"age" : 27
    		}, {
    			"firstName" : "Jim", // Second Element
    			"lastName" : "Galley",
    			"age" : 41
    		}] // End "sales" Array.
    	}// End Employees
    
    	alert(employees.sales[1].firstName);//
    	alert(employees.sales[1]["lastName"]);
    }</span>

    通过AJAX接收JSON数据
    通过AJAX接收JSON数据有三个不同方式.委派,回调与解释.
    通过委派得到JSON
     
    这种方法没有标准命名约定,只是"委派法"倒是一个挺好的描写叙述名字,由于server创建的javascript表达式文件会把JSON分派到一个变量 中.当把server的返回文本作为參数传给eval函数时,someVar变量就会装载JSON对象,然后你就能够通过这个变量訪问.
    var JSONFile = "someVar = { 'color' : 'blue' }";  // example of what is received from the server.服务器返回数据演示样例
    eval(JSONFile); // Execute the javascript code contained in JSONFile.运行JSONFile中的javascript代码.
    document.writeln(someVar.color); // 输出'blue'
     
    通过回调得到JSON
     
    第二个方法预先定义一个以JSON数据作为參数的函数,然后server返回的javascript表达式中调用这个函数.这种方法叫"回调法".这个方式被广泛地应用在处理第三方JSON数据中(比如,从其他域名获取的JSON数据)
    function processData(incommingJSON) {
       document.writeln(incommingJSON.color); // 输出'blue'
    }
    // example of what is received from the server...
    var JSONFile = "processData( { 'color' : 'blue' } )";
    eval(JSONFile);
     

     

  • 相关阅读:
    参考资料
    利用docker compose启动gitlab及runner
    在gitlab上setup CI
    git ssh端口号变更之后所需要的修改
    使用Docker Image跑Gitlab
    用Docker Compose启动Nginx和Web等多个镜像
    .NET core mvc on Docker
    ubuntu 挂载windows共享目录的方法
    13-14 元旦随想
    Uva 10177 (2/3/4)-D Sqr/Rects/Cubes/Boxes?
  • 原文地址:https://www.cnblogs.com/zfyouxi/p/5210782.html
Copyright © 2011-2022 走看看