开发者

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 code开发者_开发技巧s like this.

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


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜