大佬教程收集整理的这篇文章主要介绍了无法使用python读取json数据,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
无法加载读取的 Json 数据
import Json
import pymysqL
import os
with open("C:/Feed/DATAFILE2021-02-23_15.Json","r") as myfile:
data=myfile.read()
obj = Json.loads(data)
ac_obj=obj["data"]
print(ac_obj)
Json 数据:
{
"query_status": "ok","data": [
{
"sha256_hash": "8291db6ed7f2be2e014d6ad586a2fa2021c6f59334416e1042ed88edea137d0b","sha3_384_hash": "d684410f118253b96c5799aa44e3e2ef1d9ef9728ee6ee13cd6c076368f5a9de8189779a0214e26398f4e48915284013","sha1_hash": "20590d6000caf00092b80e3bfc740c492e2f7e50","md5_hash": "ff26664f179c0a189471183aa87e3c4a","first_seen": "2021-02-23 08:46:04","last_seen": null,"file_name": "SecuriteInfo.com.Variant.Zusy.368685.25618.6070","file_size": 2684128,"file_type_mime": "application/x-dosexec","file_type": "exe","reporter": "SecuriteInfoCom","origin_country": "FR","anonymous": 0,"signature": null,"imphash": "4328f7206db519cd4e82283211d98e83","tlsh": "34C533817B3D457AE4E3C93293F3F61E4FB4920C956869FB5B79C1203DA9F0250A924B","ssdeep": "49152:z+cw5wkXuOdhlP+0ZSq5DhWNA0ZriICjez3eUDWot2K0pHcAZaRMEZpk:KcWwG1dH60tj0ZWIyEz3tWotZ2HcA7Ek","Tags": null,"code_sign": [],"intelligence": {
"clamav": null,"downloads": "20","uploads": "1","mail": null
}
},{
"sha256_hash": "3d3112ce7c1a80e0378b15c7084b1b49a9805a5e47a85a97acdd7841d0a9b40b","sha3_384_hash": "1ff30f891e4b6eb421a5181373943bf23cc8633f66cc20265450ffc255047aae308344a71a74d1794b14323c41c4276b","sha1_hash": "b24be163878f851e0b9bc5da8967879d5ff3d846","md5_hash": "e48ba1147b75508b7f58cace584373cb","first_seen": "2021-02-23 08:45:59","file_name": "SecuriteInfo.com.Trojan.GenericKDZ.73123.31244.15546","file_size": 555008,"origin_country": "US","imphash": "71b77d57e8aec8db116eba9e387ce755","tlsh": "79C4D010BBF1D035F6B266F4497992A5A93ABD717B3480CF53C626DA1A386E09c31723","ssdeep": "12288:it0DzYl40RFrFMFf7CphShPDd+ByKZz+RfCJP079DWkkV46D25sT6fVU:imDItRFZMIphShZzsyCJP0pcV46DusT7","downloads": "15","mail": null
}
}
]
}
错误日志:
TraceBACk (most recent call last):
file ".\sampletest.py",line 10,in <module>
obj = Json.loads(data)
file "C:\Program files\python38\lib\Json\__init__.py",line 357,in loads
return _default_decoder.decode(s)
file "C:\Program files\python38\lib\Json\decoder.py",line 337,in decode
obj,end = self.raw_decode(s,IDx=_w(s,0).end())
file "C:\Program files\python38\lib\Json\decoder.py",line 355,in raw_decode
raise JsONDecodeError("ExpecTing value",s,err.value) from None
Json.decoder.JsONDecodeError: ExpecTing value: line 1 column 1 (char 0)
你不需要读取文件然后 json.loads()
,你可以只使用 json.load()
并且数据对我来说很好:
import json
def read_json(path):
with open(path,'r') as file:
return json.load(filE)
data = read_json('data.json')
# pretty print the output
from pprint import pprint
pprint(data)
输出:
{'data': [{'anonymous': 0,'code_sign': [],'file_name': 'SecuriteInfo.com.Variant.Zusy.368685.25618.6070','file_size': 2684128,'file_type': 'exe','file_type_mime': 'application/x-dosexec','first_seen': '2021-02-23 08:46:04','imphash': '4328f7206db519cd4e82283211d98e83','intelligence': {'clamav': None,'downloads': '20','mail': None,'uploads': '1'},'last_seen': None,'md5_hash': 'ff26664f179c0a189471183aa87e3c4a','origin_country': 'FR','reporter': 'SecuriteInfoCom','sha1_hash': '20590d6000caf00092b80e3bfc740c492e2f7e50','sha256_hash': '8291db6ed7f2be2e014d6ad586a2fa2021c6f59334416e1042ed88edea137d0b','sha3_384_hash': 'd684410f118253b96c5799aa44e3e2ef1d9ef9728ee6ee13cd6c076368f5a9de8189779a0214e26398f4e48915284013','signature': None,'ssdeep': '49152:z+cw5wkXuOdHLP+0ZSq5DhWNA0ZriICjez3eUdWot2K0pHcAZaRMEZpk:KcWwG1dH60tj0ZWIyEz3tWotZ2HcA7Ek','tags': None,'tlsh': '34C533817B3D457AE4E3C93293F3F61E4FB4920C956869FB5B79C1203DA9F0250A924B'},{'anonymous': 0,'file_name': 'SecuriteInfo.com.Trojan.GenericKDZ.73123.31244.15546','file_size': 555008,'first_seen': '2021-02-23 08:45:59','imphash': '71b77d57e8aec8db116eba9e387ce755','downloads': '15','md5_hash': 'e48ba1147b75508b7f58cace584373cb','origin_country': 'US','sha1_hash': 'b24be163878f851e0b9bc5da8967879d5ff3d846','sha256_hash': '3d3112ce7c1a80e0378b15c7084b1b49a9805a5e47a85a97acdd7841d0a9b40b','sha3_384_hash': '1ff30f891e4b6eb421a5181373943bf23cc8633f66cc20265450ffc255047aae308344a71a74d1794b14323c41c4276b','ssdeep': '12288:it0DzYl40RFrFMFf7CphShPDd+ByKZz+RfCJP079dwkkV46D25sT6fVU:imDItRFZMIphShZzsyCJP0pcV46DusT7','tlsh': '79C4D010BBF1D035F6B266F4497992A5A93ABD717B3480CF53C626DA1A386E09c31723'}],'query_status': 'ok'}
以上是大佬教程为你收集整理的无法使用python读取json数据全部内容,希望文章能够帮你解决无法使用python读取json数据所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。