参考:http://stackoverflow.com/questions/7356694/how-to-json-stringify-a-user-defined-class-in-javascript

 

function MyClass() {
    this.a = "1a";
    this.b = "1b";
    this.c = 100;
    this.d = {
        da : "1da",
        dc : 200
    };
}

MyClass.prototype.isManual = function() {
    return true;
}

var myClass = new MyClass();
var json = JSON.stringify(myClass);
console.log(json)

console.log(myClass.isManual())
var json = JSON.stringify({"myClass": myClass, "haha": 1});
console.log(json)

结果为:

{"a":"1a","b":"1b","c":100,"d":{"da":"1da","dc":200}}
true
{"myClass":{"a":"1a","b":"1b","c":100,"d":{"da":"1da","dc":200}},"haha":1}

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-22
  • 2022-12-23
  • 2022-12-23
  • 2021-12-09
猜你喜欢
  • 2022-01-10
  • 2022-02-10
  • 2022-12-23
  • 2022-12-23
  • 2021-08-06
  • 2022-12-23
  • 2021-09-22
相关资源
相似解决方案