我有一个名为test.json的mongo集合,我无法从python中读取test.json。如果我运行下面的代码则给出错误
ValueError:无法解码JSON对象
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>HomePage</title>
<script src="JavaScript/SpryMenuBar.js" type="text/javascript"></script>
<link href="styles/SpryMenuBarVertical.css" rel="stylesheet" type="text/css" />
</head>
<ul id="MenuBar1" class="MenuBarVertical">
<li><a href="#">Update Limit</a></li>
</li>
<li><a href="#">Delink Account</a></li>
<li><a href="#">Edit CardNumber</a>
</li>
<li>
<a href="#">Linked Accounts</a>
</li>
<li><a href="#">SMS Alerts</a>
<li><a href="#">Join Account</a>
</ul>
<p> </p>
<p> </p>
<hr />
<hr />
<form>
<p>
Client Details
<hr />
<hr />
</p>
<p>Mobile Number:-
<label>
<input type="text" name="mobilenumber" id="mobilenumber" />
</label>
</p>
<p>Country:-
<label>
<input type="text" name="country" id="country" />
</label>
</p>
<input type="submit" formaction="Search" formmethod="post" name="New" id="New" value="Search" />
<p> Title:-
<input type="text" name="Title" id="Title" value='Mr' />
</p>
<p>Middle Name:-
<label>
<input type="text" name="MiddleName" id="Middle Name" />
</label>
</p>
<p>Address:-
<label>
<input type="text" name="address" id="address" />
</label>
</p>
<p>City:-
<label>
<input type="text" name="City" id="City"value='AWENDO'/>
</label>
</p>
<p>Type of ID:-
<label>
<input type="text" name="Idtype" id="Idtype" value='Driving License' />
</label>
</p>
<p>Elma ID:-
<label>
<input type="text" name="elmaid" id="elmaid" value='1916507095'/>
</label>
</p>
<p>First Name:-
<label>
<input type="text" name="firstname" id="firstname" value='Pramod1' />
</label>
</p>
<p>Last Name:-
<label>
<input type="text" name="LastName" id="LastName" value='Sahoo'/>
</label>
</p>
<p>Registration Branch:-
<label>
<input type="text" name="registrationbranch" id="registrationbranch" />
</label>
</p>
<p>Email address:-
<label>
<input type="text" name="emailid" id="emailid" value='Pramodk@CS.com' />
</label>
</p>
<p>ID No:-
<label>
<input type="text" name="idno" id="idno" />
</label>
</p>
<hr />
<hr />
<p>
Account Details
<hr />
<hr />
</p>
<p>Bank A/C id :-
<label>
<input type="text" name="accountid" id="accountid"value='001001000095' />
</label>
</p>
<p>Transaction Limit:-
<label>
<input type="text" name="transactionlimit" id="transactionlimit" />
</label>
</p>
<p>Currency:-
<input type="text" name="currency" id="currency"value='KES'/>
</p>
<p>Daily Limit:-
<label>
<input type="text" name="dailylimit" id="dailylimit" value='500000.0000'/>
</label>
</p>
<p>
<input type="submit"formaction="Connectioncheck" formmethod="post"name="Update" id="Update" value="Update" />
</p>
<p> </p>
<hr />
Account List
<hr />
<table
<tr>
<td colspan=4 align="center"
style="background-color:teal">
<b>User Record</b></td>
</tr>
<tr style="background-color:lightgrey;">
<td><b>Record Number: </b></td>
<td><b>Card Number: </b></td>
<td><b>MiddleName:</b></td>
<td><b>BankAccountID:</b></td>
<td><b>CurrencyID:</b></td>
<td><b>DayTransactionLimit:</b></td>
<td><b>Select:</b></td>
</tr>
<tr>
<td>1</td>
<td>kenya</td>
<td>K</td>
<td>432342423</td>
<td></td>
<td>100000.0000</td>
<td><input type ="button" id="getid" onclick="getbuttonid()" value="1"></td>
<tr>
<td>2</td>
<td>kenya</td>
<td>Kumar11</td>
<td>78788787878</td>
<td>OOOPP</td>
<td>100000.0000</td>
<td><input type ="button" id="getid" onclick="getbuttonid()" value="2"></td>
<tr>
<td>3</td>
<td>kenya</td>
<td>Kb1</td>
<td>001001000095</td>
<td>KES</td>
<td>500000.0000</td>
<td><input type ="button" id="getid" onclick="getbuttonid()" value="3"></td>
</table>
</table
<hr />
Behind the Scene
<hr />
<p>Created By:-
<label>
<input type="text" name="createdby" id="createdby" />
</label>
</p>
<p>Created On:-
<label>
<input type="text" name="createdon" id="createdon" />
</label>
</p>
<p>Modified By:-
<label>
<input type="text" name="modifiedby" id="modifiedby" />
</label>
</p>
<p>Modified On:-
<label>
<input type="text" name="modifiedon" id="modifiedon" />
</label>
</p>
<p>Supervised By:-
<label>
<input type="text" name="supervisedby" id="supervisedby" />
</label>
</p>
<p>Supervised On:-
<label>
<input type="text" name="supervisedon" id="supervisedon" />
</label>
</p>
<p>
<input type="submit" name="Add" id="Add" value="Add" formmethod="post" formaction="AddController" />
<input type="submit" name="Edit" id="Edit" value="Edit" formmethod="post" formaction="EditController" />
<input type="submit" name="Save" id="Save" value="Save" />
<input type="submit" name="Cancel" id="Cancel" value="Cancel" />
<input type="submit" name="Recreate Key" id="Recreate Key" value="Recreate Key" />
<input type="submit" name="Reset Password" id="Reset Password" value="Reset Password" />
</p>
</form>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgRight:"SpryAssets/SpryMenuBarRightHover.gif"});
function getbuttonid(){
var id = document.getElementById('getid').value;
alert(id);
}
</script>
test.json
from bson import ObjectId
import json
from pprint import pprint
with open('E:/Work/Paths/Production/test.json') as data_file:
data = json.load(data_file)
pprint(data)
答案 0 :(得分:0)
实际上你提出的test.json文件不是一个有效的json,它可以被视为每一行都是一个json对象,以'{'开头,以'}'结尾,但不是整个文件整体。您应该将其作为普通文件阅读,然后应用一些技术将其加载为json。