has a json file as follows:
{
"cover": "http://p2.music.126.net/wsPS7l8JZ3EAOvlaJPWW-w==/109951163393967421.jpg?param=140y140",
"title": "2018上半年最热新歌TOP50",
"author": "网易云音乐",
"times": "1264万",
"url": "https://music.163.com/playlist?id=2303649893",
"id": "2303649893"
}
{
"cover": "http://p2.music.126.net/wpahk9cQCDtdzJPE52EzJQ==/109951163271025942.jpg?param=140y140",
"title": "你的青春里有没有属于你的一首歌?",
"author": "mayuko然",
"times": "4576万",
"url": "https://music.163.com/playlist?id=2201879658",
"id": "2201879658"
}
when I try to read the file with pd.read_json('data.json')
, I get an error. The error part is as follows:
File "D:\python\lib\site-packages\pandas\io\json\json.py", line 853, in _parse_no_numpy
loads(json, precise_float=self.precise_float), dtype=None)
ValueError: Trailing data
after a baidu found that it was a json format error, is the first time I know there is such a thing as jsonviewer. You need to save the dictionary in the file as an element in the list, modified as follows.
[{
"cover": "http://p2.music.126.net/wsPS7l8JZ3EAOvlaJPWW-w==/109951163393967421.jpg?param=140y140",
"title": "2018上半年最热新歌TOP50",
"author": "网易云音乐",
"times": "1264万",
"url": "https://music.163.com/playlist?id=2303649893",
"id": "2303649893"
},
{
"cover": "http://p2.music.126.net/wpahk9cQCDtdzJPE52EzJQ==/109951163271025942.jpg?param=140y140",
"title": "你的青春里有没有属于你的一首歌?",
"author": "mayuko然",
"times": "4576万",
"url": "https://music.163.com/playlist?id=2201879658",
"id": "2201879658"
}]
another method is to file each behavior of a complete dictionary, and then modify the parameters in the function pd. Read_json ('data.json',lines=True)
. lines
default to False
, set to True
can read json objects according to the row. In the psor.read_json document, it is explained as follows:
lines: Boolean, default False. Read the file as a json object perline.new in version 0.19.0.
the modified json file is as follows:
{"cover": "http://p2.music.126.net/wsPS7l8JZ3EAOvlaJPWW-w==/109951163393967421.jpg?param=140y140","title": "2018上半年最热新歌TOP50","author": "网易云音乐","times": "1264万","url": "https://music.163.com/playlist?id=2303649893","id": "2303649893"}
{"cover": "http://p2.music.126.net/wpahk9cQCDtdzJPE52EzJQ==/109951163271025942.jpg?param=140y140","title": "你的青春里有没有属于你的一首歌?","author": "mayuko然","times": "4576万","url": "https://music.163.com/playlist?id=2201879658","id": "2201879658"}
div>
Read More:
- Error in data training: valueerror: unknown label type: ‘continuous‘
- How to Fix Sklearn ValueError: This solver needs samples of at least 2 classes in the data, but the data
- Error in machine learning training data (FIT): valuee rror:Unknown label type:‘continuous‘
- Storing JSON data in session storage
- Unable to read workspace file ‘D:\angular.json‘: Invalid JSON character: “ “ at
- JSON data format net.sf.json .JSONException: A JSONObject text must begin with ‘{‘ at character 1 of Error:(f…
- Error reading JSON file: json.decoder.JSONDecodeError : Extra data: line 6 column 2 (char 1329)
- ValueError: Expected more than 1 value per channel when training, got input size torch.Size([1, 256,
- Python Numpy.ndarray ValueError:assignment destination is read-only
- pandas parse_ Data exception, automatically skip
- R reads JSON data
- Solution pandas.errors.ParserError : Error tokenizing data. C error: Buffer overflow caught
- Python error: pandas.errors.ParserError: Error tokenizing data. C error: Expected 3……
- 【ipfs-api】npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
- To solve the problem of failed to load: data in HTML5 game running rmmv locally/ actors.json problem
- Python read / write file error valueerror: I/O operation on closed file
- Redis reports an error when integrating springsecurity: could not read JSON: unrecognized field “enabled”“
- User defined profile in vscode settings.json And default configuration defaultSettings.json
- Unable to read meta data for class
- Mixing iteration and read methods would lose data