Json to string. if native JSON.stringify not exists.


/ Published in: JavaScript
Save to your folder(s)



Copy this code and paste it in your HTML
  1. if(typeof window.JSON=='undefined') {
  2. window.JSON = {
  3. parseJSobject : function (object) {
  4. var temp = '{';
  5. var s = 0;
  6. for(i in object) {
  7. if(s) { temp+=','; }
  8. temp += '"'+i+'":';
  9. if(typeof object[i] == 'object') {
  10. temp += this.parseJSobject(object[i]);
  11. } else {
  12. temp += '"'+object[i]+'"';
  13. }
  14. s++;
  15. }
  16. temp += '}';
  17. return temp;
  18. },
  19. stringify : function(data){
  20. return this.parseJSobject(data);
  21. }
  22. };
  23. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.