如何用js定義數組,用js來拼接json欄位

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   io   java   ar   strong   

定義js數組的方式有:

var arr = ();var arr = [];var arr = new Array();

如何拼接成一個json欄位。

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><HTML> <HEAD>  <TITLE> obj TO JSON Demo </TITLE>  <META NAME="Generator" CONTENT="EditPlus">  <META NAME="Author" CONTENT="">  <META NAME="Keywords" CONTENT="">  <META NAME="Description" CONTENT=""> </HEAD><SCRIPT type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></SCRIPT><script type="text/javascript" src="js/jquery.json-2.4.min.js"></script> <BODY> <h2>利用jquery-json將js對象轉化為JSON床</h2> <INPUT TYPE="button" VALUE="產生JSON串" ONCLICK="" id="testBut"><br/> <div id="showDiv" style="display:none">     <div> </BODY> <script type="text/javascript">    function student(sid,name,age,classInfo){        this.sid=sid;        this.name=name;        this.aeg=age;        this.classInfo=classInfo;    }    function classInfo(classname,teacher){        this.classname=classname;        this.teacher=teacher;    }    $(function(){        $("#testBut").click(function(){            var students = new Array();                arry = new classInfo(‘三年級一班‘,‘項正偉‘);                students[0]=new student(2014001,‘蔡子旭‘,23,arry);                students[1]=new student(2014002,‘張苞‘,24,arry);                students[2]=new student(2014003,‘張頜‘,33,arry);            var jsonStr=$.toJSON(students);            $("#showDiv").show();            $("#showDiv").text(jsonStr);        });    }); </script></HTML>

 

如何用js定義數組,用js來拼接json欄位

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.