Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/327.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从客户端接收数据时匹配JSON模式_Python_Json_Rest_Flask_Pymongo - Fatal编程技术网

Python 从客户端接收数据时匹配JSON模式

Python 从客户端接收数据时匹配JSON模式,python,json,rest,flask,pymongo,Python,Json,Rest,Flask,Pymongo,我编写了一个Flask REST实现来接收以下数据 在检查客户端的API密钥之后,服务器应该存储以下API定义中的数据。我面临的问题是,我在同一个领域“服务”下有很多条件,我希望能得到任何帮助 { "id": "string", "termsAndConditions": "string", "offererBranchId": "string", "requesterBranchId": "string", "accepted": "2017-05-24T10:06:31.

我编写了一个Flask REST实现来接收以下数据

在检查客户端的API密钥之后,服务器应该存储以下API定义中的数据。我面临的问题是,我在同一个领域“服务”下有很多条件,我希望能得到任何帮助

{
  "id": "string",
  "termsAndConditions": "string",
  "offererBranchId": "string",
  "requesterBranchId": "string",
  "accepted": "2017-05-24T10:06:31.012Z",
  "services": [
    {
      "id": "string",
      "name": "string",
      "aggregationLevel": [
       "string"
      ],
      "aggregationMethod": [
        "string"
      ],
      "timestep": [
      "string"
      ]   
  ] 
  }
}
如果字段名“services”与其他字符串(即“id”、“termsAndConditions”等)一样有一个字符串,则我的代码如下所示

我希望接收多个字符串的整个数据,并将数据存储在字段名“services”下

您可以使用isinstance(“str”,request.json[“services”])

如果不希望值作为服务的字符串

if not isinstance("str", request.json["services"]):
    //  your code..........
if not isinstance("str", request.json["services"]):
    //  your code..........