Hi.
I don't know exactly how you are using it, since you didn't provide any source code, but that error message simply indicate you should close the dataset before performing the operation you are trying to perform. If you are using SetJSONData, try to close the dataset before calling it.
ok.
more tests... it seems none of the DB aware control can show the data also not using TGridPlugin...
Can you please provide a sample project reproducing the issue? It's more straightforward so we can check what's going on and provide the solution.
It's also not clear what your server is returning. You must be sure you are providing a JSON array to the dataset. Are you sure of that? I would suggest you log FADATA value to console to see what's there. Maybe your response is an array wrapped in the "value" property of a JSON object. That happens in some XData responses. In this case (hypothetical) you should do it this way:
FJSARRAY := TJSONArray(TJSONObject(js.Parse(FADATA))['value']));
XDataWebDataset.SetJSONData(FJSARRAY);
Have you closed the dataset before calling SetJsonData? Have you created the persistent fields in the dataset representing the object properties like id, name, detail, typeid, etc..?
I realize now that the problem in your code is that you are using TJSONArray and other Json classes from WebLib.JSON, which are there for Delphi compatibility, but you cannot cast "real" JavaScript arrays and objects to it. You should use TJS* classes from JS unit. Here is the correct code. Also, you should define the persistent fields in the dataset representing the JSON properties:
procedure TForm4.WebButton1Click(Sender: TObject);
var
FADATA: string;
FJSARRAY: TJSArray;
begin
FADATA := WebMemo1.Lines.Text;
FJSARRAY := TJSArray(TJSJson.Parse(FADATA));
xdatawebdataset1.Close;
xdatawebdataset1.SetJsonData(FJSARRAY);
xdatawebdataset1.Open;
end;
The JS classes are direct wrappers for Javascript objects, like Array and Object. It has the same properties and methods:
arr := TJSArray(TJSObject(TJSJson.Parse(data))['fields']);
for I := 0 to arr.length - 1 do
// access arr directly
Hi i now updated my TMSWebCoreSetupWrapper to last version and i have same error !!!!!
I'm having the same issue. Delphi 11 - Web Core 2.0.4.0 - XDATA 5.8.0.0
Tried with all the solutions shown in this post but without results.
Any suggestions?
[2022-10-03 16:10:48.414] [INFO] Auth server module listening at "http://+:2001/tms/xdata/music/auth"
[2022-10-03 16:10:48.708] [INFO] Api server module listening at "http://+:2001/tms/xdata/music/api"
[2022-10-03 16:10:48.708] [INFO] Servers started. Press ENTER to stop.
[2022-10-03 16:11:01.630] [INFO] GET /tms/xdata/music/auth/$model HTTP/1.1
[2022-10-03 16:11:05.832] [INFO] OPTIONS /tms/xdata/music/auth/LoginService/Login/ HTTP/1.1
[2022-10-03 16:11:05.834] [INFO] POST /tms/xdata/music/auth/LoginService/Login/ HTTP/1.1
[2022-10-03 16:11:05.841] [INFO] OPTIONS /tms/xdata/music/api/$model HTTP/1.1
[2022-10-03 16:11:05.847] [INFO] GET /tms/xdata/music/api/$model HTTP/1.1
[2022-10-03 16:11:05.847] [INFO] 401 Unauthorized on GET /tms/xdata/music/api/$model HTTP/1.1
Since version 5.7, XData requires the JWT secret to have a minimum size.
To quickly fix this in the demo, just open unit Common.Config
and set the JwtTokenSecret
to a longer size:
constructor TServerConfig.Create;
begin
AdminPassword := 'admin';
JwtTokenSecret := 'this_should_be_just_a_random_secret';
Urls := [DefaultServerUrl];
end;
Demo will be updated in the next release.
This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.