i didn't want to write this, but it's 4 days that i'm stuck on this. I've made 1000 tests, read every topic on this forum, compiled and analyzed every demo. The problem is:
I call a service via RawInvoke (all fine)
on server, i execute a query, and i create a json stream with records. I use Firedac / TFDBatchMove / TFDBatchMoveJSONWriter, to generate a "standard" Json stream. The stream is apparently correct (i save it also on file, to see it)
on client, in an event OnResult(Response: TXDataClientResponse), i try to achieve the goal to have the records in a TWebClientDataSet, and i fail miserably. Response.Result is filled with my json stream, i can see it in dbugger.
So, first question: the only way to convert Response.Result to a TJSArray that makes "val" variable filled is
procedure OnResult(Response: TXDataClientResponse);
var
val: TJSArray;
begin
val := TJSArray( TJSJSON.parseObject( TJSJSON.stringify(Response.Result) ) );
is this correct ? There is a simpler way ? I've tried all, only this seems to work. All other tries , inspired by demos and forum topics, leave the val variable empty.
Second: with fields defined at design time in TWebClientDataSet, when i make
WebClientDataSet.Rows := val;
i have the error TypeError: Cannot read property 'Myfield' of null at Object.GetJSONDataForField
("Myfield" is the first field of the dataset). I suppose that i'm converting the Json stream in a wrong way, but i just can't find the right.
Regarding your second question, I could only answer it if I see the actual JSON you are receiving from the RawInvoke response. Remember that JSON is case-sensitive.
How is your server-side method signature declared? What is the exact response coming from the request (you can see in your network tab).
It's strange that FResult seems to be coming as string, instead of a JSON array.
Yes, indeed the reason is the TStream result, which will cause the response to be in text format. In this case, you can use what you're doing, with a slight modification:
val := TJSArray(TJSJSON.parse(String(Response.Result)));