回答此问题可获得 20 贡献值,回答如果被采纳可获得 50 分。
<p>我正在尝试将JSON API结果导出到CSV文件中。我有一个CSV格式的问题。在</p>
<h2>JSON API结果</h2>
<blockquote>
<p>{'CASSReportLink': '<a href="https://smartmover.melissadata.net/v3/Reports/CASSReport.aspx?tkenrpt=YvBDs39g52jKhLJyl5RgHKpuj5HwDMe1pE2lcQrczqRiG3/3y5yMlixj5S7lIvLJpDyAOkD8fE8vDCg56s3UogNuAkdTbS2aqoYF5FvyovUjnXzoQaHaL8TaQbwyCQ2RB7tIlszGy5+LqFnI7Xdr6sjYX93FDkSGei6Omck5OF4=" rel="nofollow noreferrer">https://smartmover.melissadata.net/v3/Reports/CASSReport.aspx?tkenrpt=YvBDs39g52jKhLJyl5RgHKpuj5HwDMe1pE2lcQrczqRiG3/3y5yMlixj5S7lIvLJpDyAOkD8fE8vDCg56s3UogNuAkdTbS2aqoYF5FvyovUjnXzoQaHaL8TaQbwyCQ2RB7tIlszGy5+LqFnI7Xdr6sjYX93FDkSGei6Omck5OF4=</a>', 'NCOAReportLink': '<a href="https://smartmover.melissadata.net/v3/Reports/NCOAReport.aspx?tkenrpt=8anQa424W7NYg8ueROFirapuj5HwDMe1pE2lcQrczqRiG3/3y5yMlixj5S7lIvLJpDyAOkD8fE8vDCg56s3UogNuAkdTbS2aqoYF5FvyovUjnXzoQaHaL8TaQbwyCQ2RB7tIlszGy5+LqFnI7Xdr6sjYX93FDkSGei6Omck5OF4=" rel="nofollow noreferrer">https://smartmover.melissadata.net/v3/Reports/NCOAReport.aspx?tkenrpt=8anQa424W7NYg8ueROFirapuj5HwDMe1pE2lcQrczqRiG3/3y5yMlixj5S7lIvLJpDyAOkD8fE8vDCg56s3UogNuAkdTbS2aqoYF5FvyovUjnXzoQaHaL8TaQbwyCQ2RB7tIlszGy5+LqFnI7Xdr6sjYX93FDkSGei6Omck5OF4=</a>', 'Records': [{'AddressExtras': '', 'AddressKey': '78704,78704', 'AddressLine1': ' , , ,STE C-100 ', 'AddressLine2': '1009 W MONROE ST ,1600 S 5TH ST ,1008 W MILTON ST ,3939 BEE CAVES RD ', 'AddressTypeCode': '', 'BaseMelissaAddressKey': '', 'CarrierRoute': '', 'City': 'Austin ,Austin ,Austin ,Austin ', 'CityAbbreviation': 'Austin ,Austin ,Austin ,Austin ', 'CompanyName': '', 'CountryCode': 'US', 'CountryName': 'United States', 'DeliveryIndicator': '', 'DeliveryPointCheckDigit': '', 'DeliveryPointCode': '', 'MelissaAddressKey': '', 'MoveEffectiveDate': '', 'MoveTypeCode': '', 'PostalCode': '78704,78704,78704,78746', 'RecordID': '1', 'Results': 'AE07', 'State': '', 'StateName': 'TX ,TX ,TX ,TX ', 'Urbanization': ''}], 'TotalRecords': '1', 'TransmissionReference': '1353', 'TransmissionResults': '', 'Version': '4.0.4.48'}
[Finished in 2.6s]</p>
</blockquote>
<h2>Python查询</h2>
<pre><code>r = response.json()
output_1 = []
output_1.append("AddressLine2")
# Collect only Address Line 2 from the JSON output. properly encode/decode the string and add it to output_1.
for record in r['Records']:
addressline2 = record['AddressLine2']
addressline2.split(",")
print(addressline2)
output_1.append(addressline2)
print(output_1)
# Write the values to a column
with open(r"C:\users\testu\documents\travis_output.csv", 'w') as fp:
writer = csv.writer(fp, dialect = 'excel')
for val in output_1:
writer.writerow([val])
</code></pre>
<h2>结果我得到了</h2>
<p><a href="https://i.stack.imgur.com/E52DS.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/E52DS.png" alt="enter image description here"/></a></p>
<h2>我想要的结果</h2>
<p><a href="https://i.stack.imgur.com/MHvp2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/MHvp2.png" alt="enter image description here"/></a></p>
<p>我认为addressline2.split(“,”)应该可以完成它的工作,但是它没有工作。谢谢你的帮助!在</p>