A relatively generic JSON response structure that contains two parts: metadata and return values

Source: Internet
Author: User

    • 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.