Traceback (most recent call last):
File "dataDeal.py", line 28, in <module>
createJson("/home/wcs/train2014.json","/home/wcs/train")
File "dataDeal.py", line 8, in createJson
data=json.load(f)
File "/home/wcs/anaconda2/lib/python2.7/json/__init__.py", line 291, in load
**kw)
File "/home/wcs/anaconda2/lib/python2.7/json/__init__.py", line 339, in loads
return _default_decoder.decode(s)
File "/home/wcs/anaconda2/lib/python2.7/json/decoder.py", line 364, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/home/wcs/anaconda2/lib/python2.7/json/decoder.py", line 382, in raw_decode
raise ValueError("No JSON object could be decoded")

ValueError: No JSON object could be decoded

我遇到这个错误是因为JSON手写出错大概是这样

{
"info":{
"description":"the train dog images",
"url":,
"version":"1.0",
"year":2017
},
"images":[]
}

在我的url 那里不能空着只留下逗号在,所以估计遇到这个错误的一个原因应该是JSON 文件有误,检查你写的是否有误请把你的内容复制到这里https://jsonformatter.curiousconcept.com/    在线检查一下就好了

下面再附上我写JSON文件的程序作为参考,这个是制作图片信息的程序

import json
import os
from PIL import Image


def createJson(path,dogPath):
with open(path,'r') as f:
data=json.load(f)
imagesInfo=[]
typeFiles=os.listdir(dogPath)
for dog in typeFiles:
dogImages=os.listdir(os.path.join(dogPath,dog))
for dogImg in dogImages:
imgPath=os.path.join(dogPath,dog,dogImg)
img=Image.open(imgPath)
width=img.size[0]
height=img.size[1]
idNum=dogImg.split('.')[0]
dogDict={'license':dog,'file_name':dogImg,'height':height,'width':width,'id':idNum}
imagesInfo.append(dogDict)
data['images']=imagesInfo
with open(path,'w') as file:
json.dump(data,file)

createJson("/home/wcs/train2014.json","/home/wcs/train")

第一个参数不用说就是你要写入的JSON文件,第二个参数是传入的图片文件路径 train 下还有很多文件夹,里面是图片

结果会是这样

{"info": {"version": "1.0", "description": "the val dog images", "year": 2017}, "images": [{"id": "1601053770,2434600106", "file_name": "1601053770,2434600106.jpg", "width": 636, "license": "81", "height": 433}, {"id": "566704649,1846734015", "file_name": "566704649,1846734015.jpg", "width": 350, "license": "81", "height": 450}, {"id": "3134450397,2844321447", "file_name": "3134450397,2844321447.jpg", "width": 600, "license": "81", "height": 387}, {"id": "1181240440,1441438354", "file_name": "1181240440,1441438354.jpg", "width": 780, "license": "81", "height": 517}, {"id": "1536683132,3786087832", "file_name": "1536683132,3786087832.jpg", "width": 575, "license": "81", "height": 512}, {"id": "608206698,1961451584", "file_name": "608206698,1961451584.jpg", "width": 529, "license": "81", "height": 800}, {"id": "2909808636,1613402380", "file_name": "2909808636,1613402380.jpg", "width": 300, "license": "81", "height": 300}, {"id": "2151502926,1713523353", "file_name": "2151502926,1713523353.jpg", "width": 600, "license": "81", "height": 339}, {"id": "326703502,1581517315", "file_name": "326703502,1581517315.jpg", "width": 640, "lic

问题: json .loads(xxx)后报错 ValueError : No JSON object could be decode d 原因:注意是unicode编码和'单引号问题引起 方法一:将xxx先作字符串转化xxx.replace("u", "").replace("'", '"'),然后再 json .loads(xxx.replace("u", "").replace("'", '"'))即可 方法二:使用 Python 内置函数eval(expression[, globals[, locas]]解
本人使用爬虫从某 数据 库中下载了一批 数据 ,本地存为 json 格式(pgp. json )然后使用 python 中的 json 模块进行 解析 json .load),一直出现下述错误 从google中查找到了同样错误的帖子,尝试修改编码方式,可一直未能解决。由于这个错误没有给出具体的错误来源,很难定位问题所在,这个问题一直困扰了一天,知道无意间了解了simple json 这个模块。 于是使用simplejso...
更改文件后,会出现异常 ValueError : No JSON object could be decode d 原因:文件内容从不带BOM的utf-8编码变成了带BOM的utf-8编码 解决方案: 方法1:以nodpad++打开文件---》编码----》转为UTF-8无BOM编码格式----》保存        2.用十六进制编辑器打开文件,删除前三个十六进制字符...
爬取淘宝MM的图片 ,发现切换页面,URL都不改变。最后了解到网页是AJAX技术实现的。 百度下,AJAX全称Asynchronous JavaScript and XML ,是指异步JavaScript和XML,跨浏览器动态生成Web应用内容的功能。简单点说,就是在不切换页面的情况下,和服务器端进行 数据 的交换。 如此模拟打开AJAX网页,服务将会返回 json 格式的 数据 给你,采用 json 模块中
import json str = '{"data_source":"favourites","desease_id":"demo_bladder_liuzhuowei","start":0,"size":10,"show_entry_flag":False,"perms":{"prdb":{"patient":{"node_ids":null}}}}' json = json .loads(str) print json Traceback (most recent call
Traceback (most recent call last): File "L:\TD\01_TD\Dev\test\test_Memory.py", line 4, in <module> print json .loads(str(a)) File "C:\Users\wangshuo\AppData\Local\anaconda3\envs\ python 2.7.18\lib\ json \__init__.py", line 339, in loads return _default_ decode r. decode (s) File "C:\Users\wangshuo\AppData\Local\anaconda3\envs\ python 2.7.18\lib\ json \ decode r.py", line 364, in decode obj, end = self.raw_ decode (s, idx=_w(s, 0).end()) File "C:\Users\wangshuo\AppData\Local\anaconda3\envs\ python 2.7.18\lib\ json \ decode r.py", line 382, in raw_ decode raise ValueError ("No JSON object could be decode d") ValueError : No JSON object could be decode d Process finished with exit code 1 使用notepad++把文件转成utf-8格式依然报错,添加encoding=‘utf-8’也是报错 所以转换了一下思路,修改了代码 with open(model_path, 'rb') as reader: model = pickle.load(reader) # model = json .load(reader) 改前的 同样在import部分也要导入pickle import pickle # import
raini@biyuzhe:~/pyspark_project/mysql1/anqu/ python /anquProduct/Server/insertDataHql$ curl -i -H "Content-Type: application/ json " -X POST -d '{"appIds": [{"appid": "1076877374"}, {"appid": "1 File "C:\ Python 27\lib\ json \__init__.py", line 290, in load **kw) File "C:\ Python 27\lib\ json \__init__.py", line 351, in loads return cls(encoding=encoding, **kw). decode (s) File "C:\ Python 27\li...
import tushare as ts df = ts.get_hist_data('sh600016',start='2016-06-23',end='2018-12-30') 当我运行上面的代码 ,出现 ValueError : No JSON object could be decode d这个错误。 这个问题出现的原因不是很明了,但是解决的方法很奇特,竟然是因为whitespace miss...
from _ctypes import Union, Structure, ArrayImportError: DLL load failed while importing _ctypes nnUnet测试