Wandering about for the first time in the Json classed of Berlin, I have a few questions from a noob perspective, which I hope someone with experience can enlighten me on.
I am implementing the JsonRPC protocol, where a request basically looks like this:
I.e. The method name may vary, and with it the “params” – or implicitly, the type of the JSon object that recides in “params”. The challenge here is that I don’t know the type, until I have identified the content of “method”.
Using TJSon, it is trivial to get the value – but relatively costly, since it will also parse “params” – which can be large and complex.
// property fields omitted for brevity
class TJSonRPC = class
property jsonrpc: String;
property method: String;
property params: String;
property id: String;
And if I parse
rpc := TJSon.JsonToObject(ReceivedJsonString);
“rpc” will contain the correct string values in the “jsonrpc”, “method” and “id” fields – while “params” will be an empty string, since it was an unknown object type.
I use “method” to look up the associated “params” type, as well as the handler methods. Now I have to reparse the whole thing again – instead of avoiding the first parsing of params, and then only parsing params with the right type later.
So, after this long intro – my question is: Can I persuade TJSon to treat “params” as it was a string and not an object for the TJsonRPC class?