相思资源网 Design By www.200059.com
<script type="text/javascript">
  /**
   * 将JS的任意对象输出为json格式字符串
   * @param {Object} _obj: 需要输出为string的对象
   */
  var obj2String = function(_obj) {
    var t = typeof (_obj);
    if (t != 'object' || _obj === null) {
      // simple data type
      if (t == 'string') {
        _obj = '"' + _obj + '"';
      }
      return String(_obj);
    } else {
      if ( _obj instanceof Date) {
        return _obj.toLocaleString();
      }
      // recurse array or object
      var n, v, json = [], arr = (_obj && _obj.constructor == Array);
      for (n in _obj) {
        v = _obj[n];
        t = typeof (v);
        if (t == 'string') {
          v = '"' + v + '"';
        } else if (t == "object" && v !== null) {
          v = this.obj2String(v);
        }
        json.push(( arr "' + n + '":') + String(v));
      }
      return ( arr "result" : {
      "fs" : {
        "TSP.IBR.MIRROR" : [{
          "_value" : "1.0",
          "_class" : 4
        }],
        "TSP.IBR.GET_FNAMES" : [{
          "_value" : "0.0",
          "_class" : 4
        }],
        "TSP.IBR.GET_TOKEN_ID" : [{
          "_value" : "0.0",
          "_class" : 4
        }],
        "TSP.IBR.INFO" : [{
          "_value" : "0.0",
          "_class" : 4
        }]
      }
    },
    "isCanceled" : false,
    "e" : "",
    "isResponsed" : true,
    "aoqSize" : 0,
    "isAsyncPost" : false,
    "code" : 0,
    "reqUID" : "xxxx-xxxxxx-xxxxx-6c2f17bb-ea18-42ec-98fa-3f63b8d26aba-nd-rq",
    "version" : "1.0",
    "fName" : "TSP.IBR.GET_FNAMES",
    "message" : "成功获取 4 个功能",
    "dir" : "DOWN",
    "nodeTime" : 1362462128706,
    "isKeyCompressed" : false,
    "seq" : 2
  }
  alert(obj2String(obj))
</script>
标签:
任意对象,json

相思资源网 Design By www.200059.com
广告合作:本站广告合作请联系QQ:858582 申请时备注:广告合作(否则不回)
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
相思资源网 Design By www.200059.com

评论“js Object2String方便查看js对象内容”

暂无js Object2String方便查看js对象内容的评论...