Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/298.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/1/vb.net/16.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_Python 3.x_Python 2.7 - Fatal编程技术网

用Python确定JSON结构

用Python确定JSON结构,python,json,python-3.x,python-2.7,Python,Json,Python 3.x,Python 2.7,我在数据库中有一个表,其中一列包含一些JSON 在每一行中,单独的JSON将略有不同。每个都将包含JSON的一些属性,但没有一个将包含所有属性。比如说 { "testAssignmentName": "RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb" } 及 及 及 及 有没有一段代码可以让我提取整个结构,这样我就可以解析JSON,而不会丢失代码后面部分中的任何属性 谢谢您可以尝试以下方法: import json

我在数据库中有一个表,其中一列包含一些JSON

在每一行中,单独的JSON将略有不同。每个都将包含JSON的一些属性,但没有一个将包含所有属性。比如说

{
    "testAssignmentName": "RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb"
} 

有没有一段代码可以让我提取整个结构,这样我就可以解析JSON,而不会丢失代码后面部分中的任何属性


谢谢

您可以尝试以下方法:

import json

jsonstring = """{
            "requirements": "RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb",
            "testSkill": {
                "testProfileId": 21,
                "educationalLevelId": 17
            },
            "primaryPooltrial": {
                "mainTestSkill": {
                    "testSkill": {
                        "testProfileId": 21,
                        "educationalLevelId": 17
                    }
                },
                "results": []
            }
        }"""

data = json.loads(jsonstring)
print (data)
RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb
这将产生以下结果:

{'requirements': 'RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb', 'primaryPooltrial': {'mainTestSkill': {'testSkill': {'educationalLevelId': 17, 'testProfileId': 21}}, 'results': []}, 'testSkill': {'educationalLevelId': 17, 'testProfileId': 21}}
您还可以选择以下选项:

print (data["requirements"])
并获得以下信息:

import json

jsonstring = """{
            "requirements": "RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb",
            "testSkill": {
                "testProfileId": 21,
                "educationalLevelId": 17
            },
            "primaryPooltrial": {
                "mainTestSkill": {
                    "testSkill": {
                        "testProfileId": 21,
                        "educationalLevelId": 17
                    }
                },
                "results": []
            }
        }"""

data = json.loads(jsonstring)
print (data)
RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb

不清楚你需要什么。如果你只是照原样通过了所有这些,那么你以后就不会错过任何东西了。谢谢你的回复。我想得到的是所有属性的单一列表,包括它们的继承权。我在这里缺少的其他json字符串中可能有一堆属性。
print (data["requirements"])
RhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarbRhubarb