JsonAPI - 发送对象列表(数组)

时间:2017-07-25 11:35:53

标签: post json-api

找不到以JsonAPI格式发送对象列表的示例。 例如,这是一个对象:

{
"data": {
    "type": "filetype",
    "id": "c33e05b7-8f55-4ee1-8d61-5b5da9110b2f",
    "attributes": {
        "created_at": "2017-07-02T09:11:10.005351Z",
        "updated_at": "2017-07-02T09:11:10.005374Z",
        "created_by": "USER_ID",
        "url_page": null,
        "resource_urls": null,
        "attachment_type_id": "1",
        "url_type_id": "1",
        "url_version": null
    },
    "relationships": {
        "item": {
            "data": {
                "type": "items",
                "id": "f0c2e244-ec02-4a75-bd36-da1f703136e7"
            }
        }
    }
 }
}

这些对象的列表(数组)应该如何看作有效的JsonAPI?

1 个答案:

答案 0 :(得分:0)

调查documentation,我会说是这样的:

{  
   "data":[  
      {  
         "type":"filetype",
         "id":"c33e05b7-8f55-4ee1-8d61-5b5da9110b2f",
         "attributes":{  
            "created_at":"2017-07-02T09:11:10.005351Z",
            "updated_at":"2017-07-02T09:11:10.005374Z",
            "created_by":"USER_ID",
            "url_page":null,
            "resource_urls":null,
            "attachment_type_id":"1",
            "url_type_id":"1",
            "url_version":null
         },
         "relationships":{  
            "item":{  
               "data":{  
                  "type":"items",
                  "id":"f0c2e244-ec02-4a75-bd36-da1f703136e7"
               }
            }
         }
      },
      {  
         "type":"filetype",
         "id":"cc06bbb5-b4f8-4351-90f3-01df3f3f2116",
         "attributes":{  
            "created_at":"2017-08-02T09:11:10.005351Z",
            "updated_at":"2017-08-02T09:11:10.005374Z",
            "created_by":"USER_ID",
            "url_page":null,
            "resource_urls":null,
            "attachment_type_id":"1",
            "url_type_id":"1",
            "url_version":null
         },
         "relationships":{  
            "item":{  
               "data":{  
                  "type":"items",
                  "id":"b0300df2-365e-44b4-bfc4-f3170dca2289"
               }
            }
         }
      }
   ]
}