i want to create an anonymous class in vb.net exactly like this:
var data = new {
total = totalPages,
page = page,
records = totalRecords,
rows = new[]{
new {id = 1, cell = new[] {"1", "-7", "Is this a good question?"}},
new {id = 2, cell = new[] {"2", "15", "Is this a blatant ripoff?"}},
new {id = 3, cell = new[] {"3", "23", "Why is the sky blue?"}}
}
};
thx.
VB.NET 2008 does not have the
new[]construct, but VB.NET 2010 does. You cannot create an array of anonymous types directly in VB.NET 2008. The trick is to declare a function like this:And have the compiler infer the type for us (since it’s anonymous type, we cannot specify the name). Then use it like:
PS. This is not called JSON. It’s called an anonymous type.