简体   繁体   中英

JSON.stringify is not working in blackberry mobile

JSON.stringify is not working in blackberry mobile it is working great in iphone and other browser. it is not prompting it in below example in blackberry mobile:

  function sup() {
        this.name;
    }

    var SUP = new sup();

        SUP.name = 'XYZ' ;
        var tt = JSON.stringify(SUP);
        alert(tt);

It sounds like that version of the Blackberry browser doesn't support the new JSON object, which was introduced in ES5 (so, just recently). You can find several polyfills/shims, including ones from the "introducer" of JSON himself .

You should create a fallback mechanism so browser uses the native JSON support if present, otherwise it download the library that @TJ Crowder pointed out

Something like this should do the trick

<script>window.JSON|| 
    document.write("<script src='js/my-json-library.js'>\x3C/script>")
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM