I have read a bit of JSON work all over the internet. as a noob, expect me to not be as good as some of you at tracking down examples, because I need knowledge to know what to search for to get knowledge. Catch22. ;-)
I'm using superobject, seems like the best way to go.
My question is, I need to separate the JSON into key/value pairs, so far I could only get value, if I know what the key is. The Key (in my app the key is the [command]) will be checked against all possible commands, and when a command matches, the value part is a comma separated list of parameters as arguments for the command that would be initiated by either side. the server/client then calls the command (a procedure/function) and passes the [commaText] as its arguments. (there may be JSON politically correct way that replaces the [commaText] and, yes, of course you may comment on that, but so far the [commaText] is a simple and easy way for me to do it.
Shorter: I need to extract both the [Key value] and the [Value value] from a JSON pair.
this is what I got working so far:
function TWebSocketServer.GetValue(const AData: String;
Key: String): String;
var
JSON: ISuperObject;
rowItem: ISuperObject;
ADataStringStream: TStringStream;
begin
ADataStringStream := TStringStream.Create(AData);
JSON := TSuperObject.ParseStream(ADataStringStream, False);
rowItem := JSON[Key];
if Assigned(rowItem) then
Result := rowItem.AsString
else Result := '';
end;
this gets me the value of the pair if I already know what the key of the pair.
Restating: need to extract both key/value as separate strings from JSON data (usually/basically ever, will I have in my possession more than one key pair, its one command/ one transmission)
More background: I have a SQLDatabase/App-Server/Many Clients implementation. (App-Server I/O <-> SQL, calculates, then output to clients, clients receive the input/function call from app-server, updates it's values, and then the user may invoke a function on the App-server, through using the client to call that function -- using websockets for communication. Both app-server and clients can call functions and procedures in the api, but It'll be one command at a time from client-server or server-client.
And I have wondered if it might not be easier to create a special case JSON parser, because my data is alway only one pair, and not a big JSON object...
Please, any suggestions will be appreciated
PS. Delphi 10.1 Berlin, Windows10 x64