REST service with empty Json 2. line

Hi!

When I make a new REST service in Datasnap (Delphi) i test it with from the web page from Embarcadero "Server Function Explorer". I get:

Executed: TServerMethods1.GetProjects

Result:

{"result":[{"ProjectID":"1","ProjectName":"Regional sale"},{"ProjectID":"2","ProjectName":"World wide sale"}]}

Perfect. A very simple Json Array with to lines of project info.

Then I make a new Tiggzi App with only one service. When I push the Test button it displays this:

{
"result": [
[
{
"ProjectID": "1",
"ProjectName": "Regional sale"
},
{
"ProjectID": "2",
"ProjectName": "World wide sale"
}
]
]
}

If you study the test result I get an ekstra bracket on line 3. Now Tiggzi is confused and when I populate the respond structure I get

Result
(Empty box)
ProjectID
ProjectName

I need help and I can't find a work around either. The service won't work event if I try to make the parameters manually.

Best regards

Ole Henrik Oftedal
Timeflex Systemer As
http://www.timeflex.com
http://www.timeflex.no
1 person has
this question
+1
This topic is no longer open for comments or replies.
  • Would you be able to share the service URL so we can test it?

    You can create the service response from sample JSON response: http://help.gotiggr.com/documentation...
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited

  • Yes of course. Here it is:

    http://timeflexstart.timeflex.no:8082...

    (No parameters needed)

    The server is set up with Bacic Authentication. But I don't think you need it in the header of the request. I have tried with both. This is a test server and there no checking on user or password.

    //Embarcadero Rad Studio Datasnap very simple REST method.
    //Returns two projects
    //No parameters needed.
    function TServerMethods1.GetProjects: TJSONArray;
    var
    Obj1, Obj2 : TJSonObject;

    begin
    //Make first array element...
    Obj1:=TJsonObject.Create;
    Obj1.AddPair('ProjectID', '1');
    Obj1.AddPair('ProjectName', 'Regional sale');

    //Second array element...
    Obj2:=TJsonObject.Create;
    Obj2.AddPair('ProjectID', '2');
    Obj2.AddPair('ProjectName', 'World wide sale');

    //Add them both to the result of the REST server method
    Result := TJSONarray.Create;
    Result.Add(Obj1);
    Result.Add(Obj2);
    end;
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited

  • I think the result is the same, when you open the URL in browser and when using Test in Tiggzi:

    In browser:


    Copied output from Tiggzi test (formatted):
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited

  • I’m thankful
    Hi Max!

    You are right (again). When I used Mozilla Firefox instead of ie i can see tha same as you.

    Do you thing its a Delphi bug? Is this legal JSON formatted code at all? I will now try the Delphi community and a bunch of other things.

    -oho
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited

  • How to recreate:

    1. Get the latest RAD Studio XE2 update 4 (the latest)
    2. Use wizzard to create New REST server
    3. Add a new server method (An array with values 1, 2, and 3)

    function TServerMethods1.GetProjects2: TJsonArray;
    begin
    Result := TJSonArray.Create;
    Result:=Result.Add(1);
    Result:=Result.Add(2);
    Result:=Result.Add(3);
    end;

    My result is this:

    {"result":[[1,2,3]]}

    Have anyone seen a result like this. Is it an array inside an array?
    And can we use that type of response in Tiggzy? There are over one million Delphi apps out there ande I bet they also want to discoever REST + Tiggzy. We are going to make them rule ... soon ... :-)
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated indifferent, undecided, unconcerned kidding, amused, unsure, silly happy, confident, thankful, excited

  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited

  • Problem solved :-)

    In stead of creating an array (TJsonArray) first, it ́s better to create a an object ( TJsonobject) first and then put everything inside this one.

    Thank you so much for all your help! The above link pointed me in the right direction. Now I can build the use my the mobilegrid automaticly by supplying this service.

    Here ́s the Delphi code to produce my test data (Two projects):

    function TServerMethods1.GetProjects2: TJsonObject;
    var
    Obj1, Obj2: TJSONobject;
    Arr: TJsonArray;

    begin
    // Make first project
    Obj1 := TJSONobject.create;
    Obj1.AddPair('ProjectID', '1');
    Obj1.AddPair('ProjectName', 'World wide sale');

    // Second project
    Obj2 := TJSONobject.create;
    Obj2.AddPair('ProjectID', '2');
    Obj2.AddPair('ProjectName', 'Latest sale');

    //Create a data array containing both projects
    Arr:=TJSonArray.Create;
    Arr.AddElement(Obj1);
    Arr.AddElement(Obj2);

    //Add the array and call it "Data"
    Result := TJSONobject.create;
    Result.Addpair('Data',Arr);

    end;
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited