您在这里似乎拥有的是csv 数据,其中一列被编码为json。
无法准确判断问题中的数据是如何引用的(最好粘贴行的repr),但我们假设它是这样的:
'"0923","41003","Permanent","{""Details"": [{""data"": {""status"": ""FAILURE"", ""id"": ""12345""}, ""DetailType"": ""Existing""}]}","2019-06-27"'
如果是这样,并且你有一个包含多行数据的文件,你可以使用 csv 模块来读取它:
import csv
import json
with open('myfile.csv', 'rb') as f:
reader = csv.reader(f)
# Remove the next line if the first row is not the headers.
# next(reader) # Skip header row.
for row in reader:
Uid, controlNo, profileType, LAStpointDetail, LastPointDate = row
# Load embedded json into a dictionary.
detail_dict = json.loads(LAStpointDetail)
# Do something with these values.
如果你只有一行作为字符串,你仍然可以使用 csv 模块:
>>> row = '"0923","41003","Permanent","{""Details"": [{""data"": {""status"": ""FAILURE"", ""id"": ""12345""}, ""DetailType"": ""Existing""}]}","2019-06-27"'
>>> # Make the data an element in a list ([]).
>>> reader = csv.reader([row])
>>> Uid, controlNo, profileType, LAStpointDetail, LastPointDate = next(reader)
>>> print Uid
0923
>>> d = json.loads(LAStpointDetail)
>>> d
{u'Details': [{u'DetailType': u'Existing', u'data': {u'status': u'FAILURE', u'id': u'12345'}}]}
>>> print d['Details'][0]['data']['status']
FAILURE