Parse JSON string for error detection

I am working with a server whose response is used in JSON format.

when the request contains valid data, they respond with a string like this

{"data": {"Results": [{"Branch": "ACCT590006"}]}}

but if the request parameters are incorrect, the answer will look like this

{"error": {"error": [{"Domain": "global", "reason": "invalid", "message": "Invalid Params"}], "code": 98865, "message": " Invalid parameter value "}}

So, questions arise, how can I determine when the server response contains an error string using an object TJSONObjectand further analyze JSON to display messages and error codes like this.

Failed reason : invalid 
Message : Invalid params 
Code: 98865 
message : invalid param value.
+3
source share
1 answer

I worked a bit with JSON, every time I knew the code (delphi 7). But I was looking a bit, and here you can find the answer to your question: http://edn.embarcadero.com/print/40882

and with a little adaptation, this should work.

Regards,
Radu

+1
source

Source: https://habr.com/ru/post/1778440/


All Articles