• 0 رای - 0 میانگین
  • 1
  • 2
  • 3
  • 4
  • 5
تبدیل json به php
#1
Exclamation 
سلام به همه
من یک فایل چند لایه json دارم که از طریق php میخوام کامل ویرایش و دوباره ارسال کنم.
کد:
{
    "variables": [],
    "info": {
        "name": "Test API",
        "_postman_id": "4f1fda5f-910c-71ac-0914-db2d0b9c6521",
        "description": "",
        "schema": "https://schema.getpostman.com/json/collection/v2.0.0/collection.json"
    },
    "item": [
        {
            "name": "Access Token",
            "request": {
                "url": "{{url}}/api/authorize/access_token",
                "method": "POST",
                "header": [],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "client_id",
                            "value": "{{clientId}}",
                            "type": "text"
                        },
                        {
                            "key": "client_secret",
                            "value": "{{clientSecret}}",
                            "type": "text"
                        },
                        {
                            "key": "grant_type",
                            "value": "client_credentials",
                            "type": "text"
                        }
                    ]
                },
                "description": "Client Credentials for Postman"
            },
            "response": []
        },
        {
            "name": "Layout create",
            "request": {
                "url": "{{url}}/api/layout?envelope=1",
                "method": "POST",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "name",
                            "value": "Postman layout",
                            "type": "text"
                        }
                    ]
                },
                "description": ""
            },
            "response": []
        },
        {
            "name": "Region create",
            "request": {
                "url": "{{url}}/api/region/24?envelope=1",
                "method": "POST",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "width",
                            "value": "300",
                            "type": "text"
                        },
                        {
                            "key": "height",
                            "value": "450",
                            "type": "text"
                        },
                        {
                            "key": "top",
                            "value": "150",
                            "type": "text"
                        },
                        {
                            "key": "left",
                            "value": "350",
                            "type": "text"
                        }
                    ]
                },
                "description": ""
            },
            "response": []
        },
        {
            "name": "Library Upload",
            "request": {
                "url": "{{url}}/api/library",
                "method": "POST",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "files",
                            "value": "",
                            "type": "file"
                        },
                        {
                            "key": "name",
                            "value": "API UPLOAD",
                            "type": "text"
                        },
                        {
                            "key": "oldMediaId",
                            "value": "249",
                            "type": "text",
                            "disabled": true
                        },
                        {
                            "key": "updateInLayouts",
                            "value": "1",
                            "type": "text",
                            "disabled": true
                        },
                        {
                            "key": "deleteOldRevisions",
                            "value": "1",
                            "type": "text",
                            "disabled": true
                        }
                    ]
                },
                "description": ""
            },
            "response": []
        },
        {
            "name": "Playlist Library Assign",
            "request": {
                "url": "{{url}}/api/playlist/library/assign/177",
                "method": "POST",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "media[]",
                            "value": "134",
                            "type": "text"
                        }
                    ]
                },
                "description": "\n"
            },
            "response": []
        },
        {
            "name": "Action: Change Layout",
            "request": {
                "url": "{{url}}/api/displaygroup/2/action/changeLayout?envelope=1",
                "method": "POST",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "layoutId",
                            "value": "24",
                            "type": "text"
                        },
                        {
                            "key": "downloadRequired",
                            "value": "true",
                            "type": "text"
                        },
                        {
                            "key": "changeMode",
                            "value": "queue",
                            "type": "text"
                        }
                    ]
                },
                "description": "Root Request\n"
            },
            "response": []
        },
        {
            "name": "Action: Overlay Layout",
            "request": {
                "url": "{{url}}/api/displaygroup/28/action/overlayLayout?envelope=1",
                "method": "POST",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "layoutId",
                            "value": "73",
                            "type": "text"
                        },
                        {
                            "key": "downloadRequired",
                            "value": "true",
                            "type": "text"
                        },
                        {
                            "key": "duration",
                            "value": "10",
                            "type": "text"
                        }
                    ]
                },
                "description": "Root Request\n"
            },
            "response": []
        },
        {
            "name": "Layouts",
            "request": {
                "url": "{{url}}/api/layout?layout=&embed=regions,playlists",
                "method": "GET",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "client_id",
                            "value": "{{clientId}}",
                            "type": "text"
                        },
                        {
                            "key": "client_secret",
                            "value": "{{clientSecret}}",
                            "type": "text"
                        },
                        {
                            "key": "grant_type",
                            "value": "client_credentials",
                            "type": "text"
                        }
                    ]
                },
                "description": "\n"
            },
            "response": []
        },
        {
            "name": "DisplayGroups",
            "request": {
                "url": "{{url}}/api/displaygroup",
                "method": "GET",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "access_token",
                            "value": "{{access_token}}",
                            "type": "text"
                        }
                    ]
                },
                "description": "\n"
            },
            "response": []
        },
        {
            "name": "Displays",
            "request": {
                "url": "{{url}}/api/display",
                "method": "GET",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {
                    "mode": "formdata",
                    "formdata": [
                        {
                            "key": "client_id",
                            "value": "lqDQiJiv8lEWi9TTddSgTGb8aIod0OLpLWP0ipnn",
                            "type": "text"
                        },
                        {
                            "key": "client_secret",
                            "value": "gKtQM7Jnt02LpnRyknuUyI7pI7xmlvW5M9bZ7LVtxC7gLzNp1IXUMfGvVNmdeoEFVkTVhKEmaIGKl9RtpnhqlVb71oq32443VuHYQgQdHvfr2iTgdN4x10Xig87QM47P2CQXQ5gn6Y6XpKuLq27flNDUtsHEyWiTirQL3HcUipL8dEbBwJzLvqDmzFoq7Q83MWs8TDkcVIuolx5qWLdeN7YLwV6liAa2gR0egmc5yUQkCGMxzx4bhGVMDywAfa",
                            "type": "text"
                        },
                        {
                            "key": "grant_type",
                            "value": "client_credentials",
                            "type": "text"
                        }
                    ]
                },
                "description": "\n"
            },
            "response": []
        },
        {
            "name": "Request Screenshot",
            "request": {
                "url": "{{url}}/api/display/requestscreenshot/33?envelope=1",
                "method": "PUT",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {},
                "description": ""
            },
            "response": []
        },
        {
            "name": "Media",
            "request": {
                "url": "{{url}}/api/library?media=API",
                "method": "GET",
                "header": [
                    {
                        "key": "Authorization",
                        "value": "Bearer {{access_token}}",
                        "description": ""
                    }
                ],
                "body": {},
                "description": ""
            },
            "response": []
        }
    ]
}
لفطا از توابع json_decode encode نگین چون اصلا به درد من نمیخوره من کامل میخوام به صورت شی گرا کار کنم مشکال من این که تعداد لایه ها زیاده
  پاسخ
تشکر شده توسط :
#2
مشکلت با json_decode چیه که میگی اینو نگید ؟؟
بعد این قضیه چه ربطی به شی گرایی داره که میگی میخوام کامل شی گرا انجام بدم !؟ خب ارایه کن تغییرت رو انجام بده دوباره ابجکت کن !
  پاسخ
تشکر شده توسط : Alaa مردی از پارس
#3
دوست عزیز تنها کاری که مینونی بگنی همین json_encode & json_decode هست
برای شیء گرایی هم اگر مطلع نیستید پارامتر دوم مهمه
کد پی‌اچ‌پی:
$x json_decode($json,true// return array eg: $x['variables']
$x json_decode($json,false// return object eg: $x->variables 
خط دوم فایل جی سان شما رو به صورت شیء یا همون object تبدیل میکنه
خط اول هم به صورت آرایه یا Array
  پاسخ
تشکر شده توسط : Alaa


پرش به انجمن:


کاربران در حال بازدید این موضوع: 1 مهمان