- Defines a relatively generic JSON response structure that contains two parts: the metadata and the return value, where the metadata indicates whether the operation succeeded with the return value message, and so on, and the return value corresponds to the data returned by the service-side method.
Public classResponse {Private Static FinalString OK = "OK"; Private Static FinalString error = "Error"; PrivateMeta Meta; PrivateObject data; PublicResponse Success () { This. Meta =NewMeta (true, OK); return This; } PublicResponse Success (Object data) { This. Meta =NewMeta (true, OK); This. data =data; return This; } PublicResponse failure () { This. Meta =NewMeta (false, ERROR); return This; } PublicResponse failure (String message) { This. Meta =NewMeta (false, message); return This; } PublicMeta Getmeta () {returnMeta; } PublicObject GetData () {returndata; } Public classMeta {Private Booleansuccess; PrivateString message; PublicMeta (Booleansuccess) { This. Success =success; } PublicMeta (Booleansuccess, String message) { This. Success =success; This. Message =message; } Public Booleanissuccess () {returnsuccess; } PublicString getMessage () {returnmessage; } }}
The response class above includes two types of common return value messages: OK and error, plus two common methods of operation: Success () and failure (), which represent the metadata structure through an inner class, which we will use more than once in the following sections.
- The JSON response structure is as follows:
{ "meta": { true, "message": "OK" }, "Data" : ...}
A relatively generic JSON response structure that contains two parts: metadata and return values