I have a simple object:
[DataContract]
public class MyClass
{
[DataMember(Name = "MyClassNo")]
public int MyClassNo { get; set; }
[DataMember(Name = "MyName")]
public string MyName { get; set; }
}
When I serialize it over my web service I get
[
{"MyClassNo": 1, "MyName": "Test1"},
{"MyClassNo": 2, "MyName": "Test2"}
]
But what I want is the data without the property names included:
[
{1, "Test1"},
{2, "Test2"}
]
How do I achieve this?
*Edit – The Code I use to serialize is:
var myObj = MyOpenSQlConnection.Query<MyClass>(@"select MyClassNo, MyName from MyTable");
return myObj.ToList<MyClass>();
Note that I’m using Dapper-dot-net to map the sql results to my object
It is impossible to do this without writing your own serializer that serializes to something other than a property hash. Hashes are sequences of key-value fields and therefore must have unique keys for each field.
If you tried blank values for each key, as in:
then what you really have is just:
since each key will overwrite the one before it.
A better question is probably, “why do you want to serialize without the property names?” Especially in web-based environments, you’re going to want to know which value corresponds to which field.