vendredi 3 novembre 2017

The best design pattern for creating dynamically JSON for API

I look for the most efficient and flexible design pattern for creating dynamically JSON that will be my API for IOS.

In example below (its only basic part) "pages", "container", "buttons" and "inputs" are dynamic. Their number and content depends request.

Now I create it that way:

foreach($pages as $page) {
    foreach($containers as $container){
        foreach($buttons as $burron){
           foreach($inputs as $inputs){

           }
        }
    }
}

The result:

{
    "callback": {
        "status": true,
        "message": "",
        "return_data": {
            "document": {
                "number": 6,
                "url": "/path/to/file",
                "document_id": 11,
                "type": 1,                  ",
                "date": "2017-10-30",
                "pages": [
                    {
                        "page_number": 1,
                        "container": [
                            {
                                "lp": 1,
                                "position": 0,
                                "buttons": [
                                    {
                                        "type": 1,
                                        "header": "Button name",
                                        "inputs": [
                                            {
                                                "type": 0,
                                                "x_pos": 160,
                                                "y_pos": 3441,
                                                "lp": 2

I hope that my question is clear. Thanks for all advice.

Aucun commentaire:

Enregistrer un commentaire