The new row count function seemed strange in JSON format response

Locked The new row count function seemed strange in JSON format response

  • Tuesday, March 24, 2009 1:36 AM
     
      Has Code
    I'm using ExtJs to comsume it, but the return JSON is strange. the count item in the same array of the data items. 

    { "d" : [
    {
    "__count": "6"
    }, {
    "__metadata": {
    "uri": "http://localhost:1859/ManagementWeb/Test/WebDataService.svc/Admin(guid\'00000000-0000-0000-0000-000000000000\')", "type": "SharpCardSystemModel.Admin"
    }, "Id": "00000000-0000-0000-0000-000000000000", "Username": "TestAdmin", "Password": "pldLZK", "Realname": "\u6d4b\u8bd5\u7ba1\u7406\u5458", "Description": "", "LastSignIn": "\/Date(-2206310400000)\/", "LastIp": "", "IsActived": true, "CreateDate": "\/Date(1236878881420)\/"
    }, {
    "__metadata": {
    "uri": "http://localhost:1859/ManagementWeb/Test/WebDataService.svc/Admin(guid\'61cc3e17-7111-4e7f-8f7c-2c9e3c5e576b\')", "type": "SharpCardSystemModel.Admin"
    }, "Id": "61cc3e17-7111-4e7f-8f7c-2c9e3c5e576b", "Username": "test11", "Password": "123", "Realname": "333", "Description": "111", "LastSignIn": "\/Date(-2206310400000)\/", "LastIp": "", "IsActived": true, "CreateDate": "\/Date(1236878881420)\/"
    }, {
    "__metadata": {
    "uri": "http://localhost:1859/ManagementWeb/Test/WebDataService.svc/Admin(guid\'6c39b832-707f-43bb-a38e-67ebd77a3594\')", "type": "SharpCardSystemModel.Admin"
    }, "Id": "6c39b832-707f-43bb-a38e-67ebd77a3594", "Username": "testadmin2", "Password": "o}$`vS", "Realname": "123", "Description": "123", "LastSignIn": "\/Date(1236788253517)\/", "LastIp": "127.0.0.1", "IsActived": true, "CreateDate": "\/Date(1236878881420)\/"
    }, {
    "__metadata": {
    "uri": "http://localhost:1859/ManagementWeb/Test/WebDataService.svc/Admin(guid\'7f5aabd8-be39-4b61-9714-b0a01aae7ec2\')", "type": "SharpCardSystemModel.Admin"
    }, "Id": "7f5aabd8-be39-4b61-9714-b0a01aae7ec2", "Username": "abc", "Password": "b##(|8", "Realname": "fff", "Description": "fff", "LastSignIn": "\/Date(-2206310400000)\/", "LastIp": "", "IsActived": false, "CreateDate": "\/Date(1236878881420)\/"
    }, {
    "__metadata": {
    "uri": "http://localhost:1859/ManagementWeb/Test/WebDataService.svc/Admin(guid\'4d145824-c775-435b-9982-b66cb7b0a44f\')", "type": "SharpCardSystemModel.Admin"
    }, "Id": "4d145824-c775-435b-9982-b66cb7b0a44f", "Username": "WebAdmin", "Password": "q%_V|?", "Realname": "\u6d4b\u8bd5", "Description": "22", "LastSignIn": "\/Date(-2208988800000)\/", "LastIp": "", "IsActived": false, "CreateDate": "\/Date(1236878881420)\/"
    }, {
    "__metadata": {
    "uri": "http://localhost:1859/ManagementWeb/Test/WebDataService.svc/Admin(guid\'fb042f01-613f-48b3-8a40-ecdc033f49aa\')", "type": "SharpCardSystemModel.Admin"
    }, "Id": "fb042f01-613f-48b3-8a40-ecdc033f49aa", "Username": "Admin", "Password": "123456", "Realname": "\u7ba1\u7406\u5458", "Description": "5511", "LastSignIn": "\/Date(1237821092510)\/", "LastIp": "127.0.0.1", "IsActived": true, "CreateDate": "\/Date(1236878881420)\/"
    }
    ] }

    it's really hard to use these data, but the Atom format looks much better. can i change this into {d:[/*data array*/], count: 9} 
    or something like this.

All Replies

  • Tuesday, March 24, 2009 8:47 AM
    Answerer
     
     Answered
    Hi Chocoboboy,

    Thanks for the feedback. The main reason for putting count inside the array is to match the Atom format we use (Count in the same level as entry). If this is causing usability issues we can certainly change it in the future. We'll look into this further.

    One thing to keep in mind is that while the element is called "__count", it really is not the count of the array. I think { d:[], totalcount:# } could serve as an alternative solution.

    Regards,

    PQ
    Peter Q.
  • Wednesday, March 25, 2009 1:16 AM
     
     
    thanks for the reply, I'm looking forward to it. for now, i will write some addition code make it work first.