如题!测试代码很简单:<script type="text/javascript">
alert(JSON);
</script>
不知是我忽略了什么,望各位指点下,谢谢!

解决方案 »

  1.   

    哪它自动生成的json都些什么内容呀
      

  2.   

    opera10.01目前好像不支持吧https://developer.mozilla.org/En/Using_native_JSON
      

  3.   


    <script type="text/javascript">
    alert(接分);
    </script>
      

  4.   

    我其他同事使用RC版本的IE8,在这些版本上是能正常alert出来的;但正式版本的就不行。
      

  5.   

    你用什么打开的,输出navigator.userAgent看看是不是ie8
      

  6.   

    我在Opera10。10上测试也还不支持
      

  7.   

    把浏览器调到 IE8 标准模式,
    自己试一下就知道咯var obj = {
        'num':123
        , 'str': 'abcde?>>"\'!@$@#%&\r\n中文ft'
        , 'dat': new Date()
        , 'reg': new RegExp('abc')
        , ary:[1,2,3, 4,5,6]
        , 'NaN': NaN
        , 'null': null
        , 'undefined':undefined
    };
    alert(JSON.stringify(obj));
      

  8.   

    下面是最简单的测试代码,各位有正式版本IE8和Opera10。10的可以试下。<html>
    <head>
    <script language="JavaScript"  type="text/javascript">
    //language="JavaScript" 使用language是为了在Opera中alert有效
    alert(navigator.userAgent)
    alert(JSON);
    </script>
    </head>
    <body>
    </body>
    </html>
      

  9.   

    btw:stringify这个方法ify是指的啥啊?
      

  10.   

    /*
    Copyright (c) 2005 JSON.orgPermission 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.
    *//*
        The global object JSON contains two methods.    JSON.stringify(value) takes a JavaScript value and produces a JSON text.
        The value must not be cyclical.    JSON.parse(text) takes a JSON text and produces a JavaScript value. It will
        return false if there is an error.
    */
    var JSON = function () {
        var m = {
                '\b': '\\b',
                '\t': '\\t',
                '\n': '\\n',
                '\f': '\\f',
                '\r': '\\r',
                '"' : '\\"',
                '\\': '\\\\'
            },
            s = {
                'boolean': function (x) {
                    return String(x);
                },
                number: function (x) {
                    return isFinite(x) ? String(x) : 'null';
                },
                string: function (x) {
                    if (/["\\\x00-\x1f]/.test(x)) {
                        x = x.replace(/([\x00-\x1f\\"])/g, function(a, b) {
                            var c = m[b];
                            if (c) {
                                return c;
                            }
                            c = b.charCodeAt();
                            return '\\u00' +
                                Math.floor(c / 16).toString(16) +
                                (c % 16).toString(16);
                        });
                    }
                    return '"' + x + '"';
                },
                object: function (x) {
                    if (x) {
                        var a = [], b, f, i, l, v;
                        if (x instanceof Array) {
                            a[0] = '[';
                            l = x.length;
                            for (i = 0; i < l; i += 1) {
                                v = x[i];
                                f = s[typeof v];
                                if (f) {
                                    v = f(v);
                                    if (typeof v == 'string') {
                                        if (b) {
                                            a[a.length] = ',';
                                        }
                                        a[a.length] = v;
                                        b = true;
                                    }
                                }
                            }
                            a[a.length] = ']';
                        } else if (x instanceof Object) {
                            a[0] = '{';
                            for (i in x) {
                                v = x[i];
                                f = s[typeof v];
                                if (f) {
                                    v = f(v);
                                    if (typeof v == 'string') {
                                        if (b) {
                                            a[a.length] = ',';
                                        }
                                        a.push(s.string(i), ':', v);
                                        b = true;
                                    }
                                }
                            }
                            a[a.length] = '}';
                        } else {
                            return;
                        }
                        return a.join('');
                    }
                    return 'null';
                }
            };
        return {
            copyright: '(c)2005 JSON.org',
            license: 'http://www.crockford.com/JSON/license.html',
    /*
        Stringify a JavaScript value, producing a JSON text.
    */
            stringify: function (v) {
                var f = s[typeof v];
                if (f) {
                    v = f(v);
                    if (typeof v == 'string') {
                        return v;
                    }
                }
                return null;
            },
    /*
        Parse a JSON text, producing a JavaScript value.
        It returns false if there is a syntax error.
    */
            parse: function (text) {
                try {
                    return !(/[^,:{}\[\]0-9.\-+Eaeflnr-u \n\r\t]/.test(
                            text.replace(/"(\\.|[^"\\])*"/g, ''))) &&
                        eval('(' + text + ')');
                } catch (e) {
                    return false;
                }
            }
        };
    }();
      

  11.   

    to wcwtitxu # (君当如狼)本地的静态页面,如何确定是否使用了兼容模式?还有不知你的测试结果如何。我发这个贴,是因为IE8说支持原生JSON,也就是可以直接使用JSON这个对象,在rc版本的IE8是能得到的,但我正式IE8中得不到这个对象,我不知究竟哪里有问题,麻烦XDJM也测试下。
      

  12.   

    to wcwtitxu # (君当如狼) 将浏览器模式和文本模式都调整为IE8模式,能够alert(JSON)对象出来,不会报对象不存在。但我的问题就来了,如果我一定要在“开发者工具”里面作这样的调整才能有该对象出来,那有何实际意义?因为普通用户都是使用默认安装的IE8,他不会去改这些设置,也不应该让用户去修改设置。而且我关掉IE8后,再打开IE8测试页面,仍然会报JSON不存在,也就是说在“开发者工具”里面作的修改只会对当前页面有效,它不会改变浏览器的全局设置。如果这样,我们现在敢用这个原生的JSON对象么?
      

  13.   

    <html>
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=8" />
    <body>
    <script type="text/javascript">
    alert(typeof JSON)
    </script>
    </body>
    </html> 或者<html>
    <head>
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
    <body>
    <script type="text/javascript">
    alert(typeof JSON)
    </script>
    </body>
    </html> 才可以使用
      

  14.   

    用什么模式, IE8是自动检测选择的.当然那个 JSON 能不能用,得自己判断一下要不然就直接用 zswang 发出来的那个 
      

  15.   

    孟老大来回贴了,激动中。我一直用的是json2.js,但JSON对象在非正式版本的IE8被IE8内置对象覆盖掉了,导致转换出了些问题;但我在正式IE8中又没有发现这个问题。既然正式版中不做特殊设置不会影响JSON对象,那我就不用担心了。感谢各位!!
      

  16.   

    IE8如何使用原生JSON对象?
    http://dotnet.aspx.cc/article/a36b0df9-d63e-423a-8a51-be827e5e62d1/read.aspx
    http://blog.csdn.net/net_lover/archive/2010/01/06/5142499.aspx
      

  17.   

    对象检测是王道。
    对象检测无法做到的,才考虑浏览器检测。
    既然许多浏览器版本不支持JSON,那么就需要检测,也就是typeof
    楼主你不会是想做个只兼容IE8的网页来吧?
      

  18.   

    本帖最后由 net_lover 于 2010-01-07 09:03:54 编辑
      

  19.   

    to # cuixiping # (愚公)我当然不是想做个只兼容IE8的网页。我有提到过一直都是用的json2.js,它里面已经就是否有JSON对象进行检测:
    if (!this.JSON) {
        this.JSON = {};
    }
    但在RC版本的IE8中,如果一个对象的属性值是空串的话,通过stringify方法转换后会把""空串变为"null"。这个应该是RC版本的bug,在正式IE8版本中,我测试发现没有这个问题了。
      

  20.   

    据测,Firefox3。5、IE8、Chrome3.0.195.38三个浏览器已内置JSON对象,而Opera最新版本10.10还不支持。
      

  21.   

    因为你页面里加了<meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7" />