Does anyone know how to change the format of the JSON that is spit out by a datasnap server? I'm returning an object to the calling method, and the JSON has all the fields and sub objects, etc, but it also includes the unit names.Class name , and Id, and the word "type". I want it to just put the names of the fields in each object and not the "extra" stuff (I guess you'd call it the "metadata"). The following is an excerpt:

Does anyone know how to change the format of the JSON that is spit out by a datasnap server?   I'm returning an object to the calling method, and the JSON has all the fields and sub objects, etc, but it also includes the unit names.Class name , and Id, and the word "type".   I want it to just put the names of the fields in each object and not the "extra" stuff (I guess you'd call it the "metadata").  The following is an excerpt:


{"result":[{"type":"USpecialNeeds.TSpecialNeeds","id":1,"fields":{"special_needs_detailed":{"type":"USpecialNeeds.TSpecialNeedsDetailed","id":2,"fields":{"years_horizon":0,"annual_inflation":0,"medical_inflation":0,"growth_rate":0,"annual_income":{"type":"USpecialNeeds.TAnnualIncome","id":3,"fields":{"annual_amount":0,"total_amount":0,"earn_years":0}}  .....

there's more, but you see where it has  "type" : "USpecialNeeds.TSpecialNeeds", "id": 1, "fields":          I don't want that in there at all, just   "special_needs_detailed": {"years_horizon" : 0, "annual_inflation" : 0,      etc....

Comments

  1. Phillip Woon you're welcome, i'm glad it helped you.
    ps: I'm learnind DataSnap now, and have a lot of questions, but I can't find good guide :(

    ReplyDelete
  2. Thanks Phillip Burton Andrew Terekhov  , I was going to ask the same question, because I have the same problem when calling Datasnap server from PHP clients, we parse the results in php, but it's will be better to return the clean json from server

    ReplyDelete
  3. You have to return a TJSONObject object in your method, and not an object of your class.   I wrote a method to convert from my class to the TJSONObject.   It'll still have the "result" : but nothing else

    ReplyDelete

Post a Comment