应用思考-教育技术论坛

标题: JSON的AS3类求版主翻译一下。 [打印本页]

作者: 龙城flash    时间: 2007-12-12 14:37
标题: JSON的AS3类求版主翻译一下。
JSON.as 类注释如下:
/*
Copyright (c) 2005 JSON.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/*
ported to Actionscript May 2005 by Trannie Carter <tranniec@designvox.com>, wwww.designvox.com
USAGE:
try {
var o:Object = JSON.parse(jsonStr);
var s:String = JSON.stringify(obj);
} catch(ex) {
trace(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
}
*/

据说在 AS 3.0 中用这个比使用 xml 快两部。

附件:
(, 下载次数: 3)
作者: 龙城flash    时间: 2007-12-12 14:48
标题: JSON 类中的方法:
JSON 类中的方法:

package {
        class JSON {
//没有声明继承的类,就是直接继承根类(Object)。

                static function stringify(arg):String

                static function parse(text:String):Object

                        function white()

                        function string()

                        function array()

                        function object()

                        function number()

                        function word()

                        function value()
                }
        }
}
作者: etthink    时间: 2007-12-12 22:04
哪里需要翻译?版权?
作者: 龙城flash    时间: 2007-12-13 19:04
:L
英文注释,不知道是什么意思。
作者: etthink    时间: 2007-12-13 19:50
标题: 大家一起来翻译,每天译几行
以跟帖形式翻译吧,最后放在一起就可以了。
  1. /*
  2. Copyright (c) 2005 JSON.org

  3. Permission is hereby granted, free of charge, to any person obtaining a copy
  4. of this software and associated documentation files (the "Software"), to deal
  5. in the Software without restriction, including without limitation the rights
  6. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. copies of the Software, and to permit persons to whom the Software is
  8. furnished to do so, subject to the following conditions:

  9. The Software shall be used for Good, not Evil.

  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  11. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  12. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  13. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  14. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  15. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  16. SOFTWARE.
  17. */

  18. /*
  19. ported to Actionscript May 2005 by Trannie Carter , wwww.designvox.com
  20. USAGE:
  21. try {
  22. var o:Object = JSON.parse(jsonStr);
  23. var s:String = JSON.stringify(obj);
  24. } catch(ex) {
  25. trace(ex.name + ":" + ex.message + ":" + ex.at + ":" + ex.text);
  26. }

  27. */
  28. package {
  29.         class JSON {

  30.                 static function stringify(arg):String {

  31.                         var c,i,l,s='',v;

  32.                         switch (typeof arg) {
  33.                                 case 'object' :
  34.                                         if (arg) {
  35.                                                 if (arg instanceof Array) {
  36.                                                         for (i=0; i < arg.length; ++i) {
  37.                                                                 v=stringify(arg[i]);
  38.                                                                 if (s) {
  39.                                                                         s+= ',';
  40.                                                                 }
  41.                                                                 s+= v;
  42.                                                         }
  43.                                                         return '[' + s + ']';
  44.                                                 } else if (typeof arg.toString != 'undefined') {
  45.                                                         for (i in arg) {
  46.                                                                 v=arg[i];
  47.                                                                 if (typeof v != 'undefined' && typeof v != 'function') {
  48.                                                                         v=stringify(v);
  49.                                                                         if (s) {
  50.                                                                                 s+= ',';
  51.                                                                         }
  52.                                                                         s+= stringify(i) + ':' + v;
  53.                                                                 }
  54.                                                         }
  55.                                                         return '{' + s + '}';
  56.                                                 }
  57.                                         }
  58.                                         return 'null';
  59.                                 case 'number' :
  60.                                         return isFinite(arg)?String(arg):'null';
  61.                                 case 'string' :
  62.                                         l=arg.length;
  63.                                         s='"';
  64.                                         for (i=0; i < l; i+= 1) {
  65.                                                 c=arg.charAt(i);
  66.                                                 if (c >= ' ') {
  67.                                                         if (c == '\\' || c == '"') {
  68.                                                                 s+= '\\';
  69.                                                         }
  70.                                                         s+= c;
  71.                                                 } else {
  72.                                                         switch (c) {
  73.                                                                 case '\b' :
  74.                                                                         s+= '\\b';
  75.                                                                         break;
  76.                                                                 case '\f' :
  77.                                                                         s+= '\\f';
  78.                                                                         break;
  79.                                                                 case '\n' :
  80.                                                                         s+= '\\n';
  81.                                                                         break;
  82.                                                                 case '\r' :
  83.                                                                         s+= '\\r';
  84.                                                                         break;
  85.                                                                 case '\t' :
  86.                                                                         s+= '\\t';
  87.                                                                         break;
  88.                                                                 default :
  89.                                                                         c=c.charCodeAt();
  90.                                                                         s+= '\\u00' + Math.floor(c / 16).toString(16) + c % 16.toString(16);
  91.                                                         }
  92.                                                 }
  93.                                         }
  94.                                         return s + '"';
  95.                                 case 'boolean' :
  96.                                         return String(arg);
  97.                                 default :
  98.                                         return 'null';
  99.                         }
  100.                 }

  101.                 static function parse(text:String):Object {
  102.                         var at=0;
  103.                         var ch=' ';

  104.                         function error(m) {
  105.                                 throw {name:'JSONError',message:m,at:at - 1,text:text};
  106.                         }

  107.                         function next() {
  108.                                 ch=text.charAt(at);
  109.                                 at+= 1;
  110.                                 return ch;
  111.                         }

  112.                         function white() {
  113.                                 while (ch) {
  114.                                         if (ch <= ' ') {
  115.                                                 this.next();
  116.                                         } else if (ch == '/') {
  117.                                                 switch (this.next()) {
  118.                                                         case '/' :
  119.                                                                 while (this.next() && ch != '\n' && ch != '\r') {
  120.                                                                 }
  121.                                                                 break;
  122.                                                         case '*' :
  123.                                                                 this.next();
  124.                                                                 for (; ; ) {
  125.                                                                         if (ch) {
  126.                                                                                 if (ch == '*') {
  127.                                                                                         if (this.next() == '/') {
  128.                                                                                                 next();
  129.                                                                                                 break;
  130.                                                                                         }
  131.                                                                                 } else {
  132.                                                                                         this.next();
  133.                                                                                 }
  134.                                                                         } else {
  135.                                                                                 error("Unterminated comment");
  136.                                                                         }
  137.                                                                 }
  138.                                                                 break;
  139.                                                         default :
  140.                                                                 this.error("Syntax error");
  141.                                                 }
  142.                                         } else {
  143.                                                 break;
  144.                                         }
  145.                                 }
  146.                         }

  147.                         function string() {
  148.                                 var i,s='',t,u;
  149.                                 var outer:Boolean=false;

  150.                                 if (ch == '"') {
  151.                                         while (this.next()) {
  152.                                                 if (ch == '"') {
  153.                                                         this.next();
  154.                                                         return s;
  155.                                                 } else if (ch == '\\') {
  156.                                                         switch (this.next()) {
  157.                                                                 case 'b' :
  158.                                                                         s+= '\b';
  159.                                                                         break;
  160.                                                                 case 'f' :
  161.                                                                         s+= '\f';
  162.                                                                         break;
  163.                                                                 case 'n' :
  164.                                                                         s+= '\n';
  165.                                                                         break;
  166.                                                                 case 'r' :
  167.                                                                         s+= '\r';
  168.                                                                         break;
  169.                                                                 case 't' :
  170.                                                                         s+= '\t';
  171.                                                                         break;
  172.                                                                 case 'u' :
  173.                                                                         u=0;
  174.                                                                         for (i=0; i < 4; i+= 1) {
  175.                                                                                 t=parseInt(this.next(),16);
  176.                                                                                 if (! isFinite(t)) {
  177.                                                                                         outer=true;
  178.                                                                                         break;
  179.                                                                                 }
  180.                                                                                 u=u * 16 + t;
  181.                                                                         }
  182.                                                                         if (outer) {
  183.                                                                                 outer=false;
  184.                                                                                 break;
  185.                                                                         }
  186.                                                                         s+= String.fromCharCode(u);
  187.                                                                         break;
  188.                                                                 default :
  189.                                                                         s+= ch;
  190.                                                         }
  191.                                                 } else {
  192.                                                         s+= ch;
  193.                                                 }
  194.                                         }
  195.                                 }
  196.                                 this.error("Bad string");
  197.                         }

  198.                         function array() {
  199.                                 var a=[];

  200.                                 if (ch == '[') {
  201.                                         this.next();
  202.                                         this.white();
  203.                                         if (ch == ']') {
  204.                                                 this.next();
  205.                                                 return a;
  206.                                         }
  207.                                         while (ch) {
  208.                                                 a.push(this.value());
  209.                                                 this.white();
  210.                                                 if (ch == ']') {
  211.                                                         this.next();
  212.                                                         return a;
  213.                                                 } else if (ch != ',') {
  214.                                                         break;
  215.                                                 }
  216.                                                 this.next();
  217.                                                 this.white();
  218.                                         }
  219.                                 }
  220.                                 this.error("Bad array");
  221.                         }

  222.                         function object() {
  223.                                 var k,o={};

  224.                                 if (ch == '{') {
  225.                                         this.next();
  226.                                         this.white();
  227.                                         if (ch == '}') {
  228.                                                 this.next();
  229.                                                 return o;
  230.                                         }
  231.                                         while (ch) {
  232.                                                 k=this.string();
  233.                                                 this.white();
  234.                                                 if (ch != ':') {
  235.                                                         break;
  236.                                                 }
  237.                                                 this.next();
  238.                                                 o[k]=this.value();
  239.                                                 this.white();
  240.                                                 if (ch == '}') {
  241.                                                         this.next();
  242.                                                         return o;
  243.                                                 } else if (ch != ',') {
  244.                                                         break;
  245.                                                 }
  246.                                                 this.next();
  247.                                                 this.white();
  248.                                         }
  249.                                 }
  250.                                 this.error("Bad object");
  251.                         }

  252.                         function number() {
  253.                                 var n='',v;

  254.                                 if (ch == '-') {
  255.                                         n='-';
  256.                                         this.next();
  257.                                 }
  258.                                 while (ch >= '0' && ch <= '9') {
  259.                                         n+= ch;
  260.                                         this.next();
  261.                                 }
  262.                                 if (ch == '.') {
  263.                                         n+= '.';
  264.                                         while (this.next() && ch >= '0' && ch <= '9') {
  265.                                                 n+= ch;
  266.                                         }
  267.                                 }
  268.                                 v=+ n;
  269.                                 if (! isFinite(v)) {
  270.                                         this.error("Bad number");
  271.                                 } else {
  272.                                         return v;
  273.                                 }
  274.                         }

  275.                         function word() {
  276.                                 switch (ch) {
  277.                                         case 't' :
  278.                                                 if (this.next() == 'r' && this.next() == 'u' && this.next() == 'e') {
  279.                                                         this.next();
  280.                                                         return true;
  281.                                                 }
  282.                                                 break;
  283.                                         case 'f' :
  284.                                                 if (this.next() == 'a' && this.next() == 'l' && this.next() == 's' && this.next() == 'e') {
  285.                                                         this.next();
  286.                                                         return false;
  287.                                                 }
  288.                                                 break;
  289.                                         case 'n' :
  290.                                                 if (this.next() == 'u' && this.next() == 'l' && this.next() == 'l') {
  291.                                                         this.next();
  292.                                                         return null;
  293.                                                 }
  294.                                                 break;
  295.                                 }
  296.                                 this.error("Syntax error");
  297.                         }

  298.                         function value() {
  299.                                 this.white();
  300.                                 switch (ch) {
  301.                                         case '{' :
  302.                                                 return this.object();
  303.                                         case '[' :
  304.                                                 return this.array();
  305.                                         case '"' :
  306.                                                 return this.string();
  307.                                         case '-' :
  308.                                                 return this.number();
  309.                                         default :
  310.                                                 return ch >= '0' && ch <= '9'?this.number():this.word();
  311.                                 }
  312.                         }

  313.                         return value();
  314.                 }
  315.         }
  316. }
复制代码

作者: etthink    时间: 2007-12-13 20:02
标题: 我翻译开关,大家继续吧
版权所有:2005 JSON.org
Copyright (c) 2005 JSON.org
允许任何人免费使用并取得软件和相关文档的拷贝,没有任何限制:可以
自由复制,修改,合并,出版,分发,重新授权或者销售。
虽然允许使用软件的人可以这样使用,但须符合下列条件:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:




欢迎光临 应用思考-教育技术论坛 (http://www.etthink.com/) Powered by Discuz! X3.4