TypeScript反序列化无法按预期工作

时间:2018-07-24 16:41:55

标签: angular typescript

我建立了一个模型类来表示一个对象。反序列化函数应使用JSON字符串填充它。

export class MyData
{
    public name:string;
    public job:string;

    public deserialize (input:any) : MyData
    {
      Object.assign (this, input);
      return this;
  }    
}

var md:MyData = new MyData ().deserialize ({ name: "max", job: "sales" }));
console.log ("md="+md);

但是md仍然是一个对象。

md=[object Object]

我在这里想念什么?谢谢!

1 个答案:

答案 0 :(得分:2)

这按预期工作。 sudo rpm --query centos-release centos-release-7-5.1804.el7.centos.2.x86_64 sudo yum install tkinter ... Package tkinter-2.7.5-69.el7_5.x86_64 already installed and latest version python -m tkinter /usr/bin/python: No module named tkinter python Python 2.7.5 (default, Jul 13 2018, 13:06:57) [GCC 4.8.5 20150623 (Red Hat 4.8.5-28)] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter Traceback (most recent call last): File "<stdin>", line 1, in <module> ImportError: No module named tkinter 将返回Object.toString()

尝试[object Object]。如果要将整个对象作为字符串,请尝试console.log(md.name)