Salvador
Salvador

Reputation: 16482

Parse JSON string to detect error response

i'm working with a server which response using the JSON format.

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

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

but if the parameters of the request are incorrect the response goes like this

{"error":{"errors":[{"domain":"global","reason":"invalid","message":"Invalid Params"}],"code":98865,"message":"Invalid param value"}}

So the questions are how i can determine when the response of the server contains a error string using the TJSONObject object and additionally parse the JSON string to show the messages and error codes like this.

Failed reason : invalid 
Message : Invalid params 
Code: 98865 
message : invalid param value.

Upvotes: 3

Views: 1483

Answers (1)

RBA
RBA

Reputation: 12584

I've worked a little with JSON, an every time I've parsed from code(delphi 7). But i've searched a little bit, and here you may find the answer of your question: http://edn.embarcadero.com/print/40882

and with a little adaption this should work.

Best regards,
Radu

Upvotes: 1

Related Questions