1

In my MVC project, I return like 300 rows, which has exact same structure (fields), so instead of this:

[{
  name : "John",
  age : 11,
}, {
  name : "Jane",
  age : 21,
}, {
  name : "Poul",
  age : 18,
}]

Is it possible, in vb.net (or c#), to only state the fieldnames once and return like this:

[["name","age"],["John",11],["Jane",21],["Poul",18]]

That would save me like 50% of the code returned from server to client.

Rubens
  • 14,478
  • 11
  • 63
  • 92
MojoDK
  • 4,410
  • 10
  • 42
  • 80
  • but then ul have to parse it to the original way when you are iterating through it. – krishwader Aug 03 '13 at 08:07
  • yes, return an `object[][]` in .Net and make your inner array contain only the values. – abc123 Aug 03 '13 at 08:10
  • 2
    It is not a problem, you should ask it to send the data compressed. You will probably save a lot more this way. – Casperah Aug 03 '13 at 08:12
  • Agree with Casperah this isn't really all that much data, and you can always request the data in zipped form. – abc123 Aug 03 '13 at 08:15
  • http://jsfiddle.net/F88qR/ – HIRA THAKUR Aug 03 '13 at 08:20
  • @MESSIAH that does it client-side he said `is it possible in vb.net (or c#) to only state the fieldnames once and return like this:` does work though :) – abc123 Aug 03 '13 at 08:24
  • possible duplicate of [Compression algorithm for JSON encoded packets?](http://stackoverflow.com/questions/395505/compression-algorithm-for-json-encoded-packets) – CodeCaster Aug 03 '13 at 08:24

1 Answers1

1

yes, return an object[][] in .Net and make your inner array contain only the values.

Example:

public object[][] GetUsers()
{
    List<object[]> users = new List<object[]>();
    //Get users and store them in variable called RealUsers or cycle through DataRows
    foreach(User user in RealUsers)
    {
        users.add(new object[]() {user.Name, user.Age});
    }

    return users.ToArray();
}
abc123
  • 17,855
  • 7
  • 52
  • 82