2012-02-28 56 views
0

我们在使用Spring MVC中的Java后端,其中实体转化为JSON与类名作为根密钥值 - 例如 -JSON输出与类名的根密钥值使用JSON .NET

{"MyPojo":{"id":4}} 这是Java/Spring框架与线实现 - objectMapper.configure(SerializationConfig.Feature.WRAP_ROOT_VALUE, true);

在JSON.NET我们有任何属性,它可以使类名是JSON作为根密钥的一部分?

回答

-1

肯定,只要有一个属性是类的,像这样的名称的匿名对象:

void Main() 
{ 
    var foo = new Foo { Bar = "baz" }; 
    JsonConvert.SerializeObject(new {Foo = foo}).ToString(); //{"Foo":{"Bar":"asdf"}} 
} 

public class Foo 
{ 
    public string Bar { get; set; } 
}