-3

我需要格式化这个字符串。这些只是 JSON 数组/对象的 6 条记录。我需要编写一个 python 代码来删除所有" ,. 我只想在一行中查看真实数据。

有人可以帮我写代码吗?我有一个截止日期..请帮忙..

{"status": "ok", "items": [{"1": {"Work_Phone_Extension": null, "Residential_Postal_OR_Zip_Code": "", "Residential_Street_Address_line_2": "", "Residential_Street_Address_line_1": "", "Work_Phone": "", "Name_Part": ["PATIENT", "TEST"], "Residence_Phone": "416-", "Mailing_City": "Toronto", "Mailing_Postal_OR_Zip_Code": "", "Mailing_Street_Address_line_2": "", "Mailing_Street_Address_line_1": "", "Cell_Phone": null, "Residential_City": "Toronto", "Residential_Country_AND_Province_OR_State": "CA_ON", "Mailing_Country_AND_Province_OR_State": "CA_ON"}, "3": {"Work_Phone_Extension": null, "Residential_Postal_OR_Zip_Code": "", "Residential_Street_Address_line_2": "", "Residential_Street_Address_line_1": "", "Work_Phone": "", "Name_Part": ["WOLFIE", "HOWLETT"], "Residence_Phone": "416-", "Mailing_City": "Toronto", "Mailing_Postal_OR_Zip_Code": "", "Mailing_Street_Address_line_2": "", "Mailing_Street_Address_line_1": "", "Cell_Phone": null, "Residential_City": "Toronto", "Residential_Country_AND_Province_OR_State": "CA_ON", "Mailing_Country_AND_Province_OR_State": "CA_ON"}, "2": {"Work_Phone_Extension": null, "Residential_Postal_OR_Zip_Code": "", "Residential_Street_Address_line_2": "", "Residential_Street_Address_line_1": "18 Yonge St", "Work_Phone": "", "Name_Part": ["Steve", "TEST"], "Residence_Phone": "416-555-5555", "Mailing_City": "Toronto", "Mailing_Postal_OR_Zip_Code": "", "Mailing_Street_Address_line_2": "", "Mailing_Street_Address_line_1": "18 Yonge St", "Cell_Phone": null, "Residential_City": "Toronto", "Residential_Country_AND_Province_OR_State": "CA_ON", "Mailing_Country_AND_Province_OR_State": "CA_ON"}, "5": {"Work_Phone_Extension": null, "Residential_Postal_OR_Zip_Code": "", "Residential_Street_Address_line_2": "", "Residential_Street_Address_line_1": "", "Work_Phone": "", "Name_Part": ["BUTTERS", "STOTCH"], "Residence_Phone": "416-", "Mailing_City": "Toronto", "Mailing_Postal_OR_Zip_Code": "", "Mailing_Street_Address_line_2": "", "Mailing_Street_Address_line_1": "", "Cell_Phone": null, "Residential_City": "Toronto", "Residential_Country_AND_Province_OR_State": "CA_ON", "Mailing_Country_AND_Province_OR_State": "CA_ON"}, "4": {"Work_Phone_Extension": null, "Residential_Postal_OR_Zip_Code": "91041", "Residential_Street_Address_line_2": "", "Residential_Street_Address_line_1": "1 Manhattan Ave.", "Work_Phone": "", "Name_Part": ["SUE", "STORM"], "Residence_Phone": "416-555-5556", "Mailing_City": "Star City", "Mailing_Postal_OR_Zip_Code": "91041", "Mailing_Street_Address_line_2": "", "Mailing_Street_Address_line_1": "1 Manhattan Ave.", "Cell_Phone": null, "Residential_City": "Star City", "Residential_Country_AND_Province_OR_State": "CA_ON", "Mailing_Country_AND_Province_OR_State": "CA_ON"}, "6": {"Work_Phone_Extension": null, "Residential_Postal_OR_Zip_Code": "", "Residential_Street_Address_line_2": "", "Residential_Street_Address_line_1": "1 Rural Rd E", "Work_Phone": "", "Name_Part": ["CLARK", "KENT"], "Residence_Phone": "416-606-0001", "Mailing_City": "Smallville", "Mailing_Postal_OR_Zip_Code": "", "Mailing_Street_Address_line_2": "", "Mailing_Street_Address_line_1": "1 Rural Rd E", "Cell_Phone": null, "Residential_City": "Smallville", "Residential_Country_AND_Province_OR_State": "CA_ON", "Mailing_Country_AND_Province_OR_State": "CA_ON"}}]}
4

1 回答 1

0
import json
l_dict = json.loads(long_string)

然后,您有一本字典,您可以根据需要对其进行格式化/迭代。

In [192]: l_dict
Out[192]: 
{u'items': [{u'1': {u'Cell_Phone': None,
    u'Mailing_City': u'Toronto',
    u'Mailing_Country_AND_Province_OR_State': u'CA_ON',
    u'Mailing_Postal_OR_Zip_Code': u'',
    u'Mailing_Street_Address_line_1': u'',
    u'Mailing_Street_Address_line_2': u'',
    u'Name_Part': [u'PATIENT', u'TEST'],
    u'Residence_Phone': u'416-',
    u'Residential_City': u'Toronto',
    u'Residential_Country_AND_Province_OR_State': u'CA_ON',
    u'Residential_Postal_OR_Zip_Code': u'',
    u'Residential_Street_Address_line_1': u'',
    u'Residential_Street_Address_line_2': u'',
    u'Work_Phone': u'',
    u'Work_Phone_Extension': None},
   u'2': {u'Cell_Phone': None,
    u'Mailing_City': u'Toronto',
    u'Mailing_Country_AND_Province_OR_State': u'CA_ON',
    u'Mailing_Postal_OR_Zip_Code': u'',
    u'Mailing_Street_Address_line_1': u'18 Yonge St',
    u'Mailing_Street_Address_line_2': u'',
    u'Name_Part': [u'Steve', u'TEST'],
    u'Residence_Phone': u'416-555-5555',
    u'Residential_City': u'Toronto',
    u'Residential_Country_AND_Province_OR_State': u'CA_ON',
    u'Residential_Postal_OR_Zip_Code': u'',
    u'Residential_Street_Address_line_1': u'18 Yonge St',
    u'Residential_Street_Address_line_2': u'',
    u'Work_Phone': u'',
    u'Work_Phone_Extension': None},
   u'3': {u'Cell_Phone': None,
    u'Mailing_City': u'Toronto',
    u'Mailing_Country_AND_Province_OR_State': u'CA_ON',
    u'Mailing_Postal_OR_Zip_Code': u'',
    u'Mailing_Street_Address_line_1': u'',
    u'Mailing_Street_Address_line_2': u'',
    u'Name_Part': [u'WOLFIE', u'HOWLETT'],
    u'Residence_Phone': u'416-',
    u'Residential_City': u'Toronto',
    u'Residential_Country_AND_Province_OR_State': u'CA_ON',
    u'Residential_Postal_OR_Zip_Code': u'',
    u'Residential_Street_Address_line_1': u'',
    u'Residential_Street_Address_line_2': u'',
    u'Work_Phone': u'',
    u'Work_Phone_Extension': None},
   u'4': {u'Cell_Phone': None,
    u'Mailing_City': u'Star City',
    u'Mailing_Country_AND_Province_OR_State': u'CA_ON',
    u'Mailing_Postal_OR_Zip_Code': u'91041',
    u'Mailing_Street_Address_line_1': u'1 Manhattan Ave.',
    u'Mailing_Street_Address_line_2': u'',
    u'Name_Part': [u'SUE', u'STORM'],
    u'Residence_Phone': u'416-555-5556',
    u'Residential_City': u'Star City',
    u'Residential_Country_AND_Province_OR_State': u'CA_ON',
    u'Residential_Postal_OR_Zip_Code': u'91041',
    u'Residential_Street_Address_line_1': u'1 Manhattan Ave.',
    u'Residential_Street_Address_line_2': u'',
    u'Work_Phone': u'',
    u'Work_Phone_Extension': None},
   u'5': {u'Cell_Phone': None,
    u'Mailing_City': u'Toronto',
    u'Mailing_Country_AND_Province_OR_State': u'CA_ON',
    u'Mailing_Postal_OR_Zip_Code': u'',
    u'Mailing_Street_Address_line_1': u'',
    u'Mailing_Street_Address_line_2': u'',
    u'Name_Part': [u'BUTTERS', u'STOTCH'],
    u'Residence_Phone': u'416-',
    u'Residential_City': u'Toronto',
    u'Residential_Country_AND_Province_OR_State': u'CA_ON',
    u'Residential_Postal_OR_Zip_Code': u'',
    u'Residential_Street_Address_line_1': u'',
    u'Residential_Street_Address_line_2': u'',
    u'Work_Phone': u'',
    u'Work_Phone_Extension': None},
   u'6': {u'Cell_Phone': None,
    u'Mailing_City': u'Smallville',
    u'Mailing_Country_AND_Province_OR_State': u'CA_ON',
    u'Mailing_Postal_OR_Zip_Code': u'',
    u'Mailing_Street_Address_line_1': u'1 Rural Rd E',
    u'Mailing_Street_Address_line_2': u'',
    u'Name_Part': [u'CLARK', u'KENT'],
    u'Residence_Phone': u'416-606-0001',
    u'Residential_City': u'Smallville',
    u'Residential_Country_AND_Province_OR_State': u'CA_ON',
    u'Residential_Postal_OR_Zip_Code': u'',
    u'Residential_Street_Address_line_1': u'1 Rural Rd E',
    u'Residential_Street_Address_line_2': u'',
    u'Work_Phone': u'',
    u'Work_Phone_Extension': None}}],
 u'status': u'ok'}
于 2013-02-06T22:21:54.467 回答