以下のようなコードがあり
実行すると以下のようになります
python
1import json 2import time 3 4def main(): 5 locdata = [] 6 7 f = open("business.txt","r",encoding='utf-8_sig') 8 for line in f: 9 json_dict = json.loads(line) 10 locdata.append([json_dict["business_id"],json_dict["latitude"],json_dict["longitude"]]) 11 12 with open("locdata(gati).txt","w") as fw: 13 for x in locdata: 14 fw.write(json.dumps(x) + "\n") 15 16if __name__ == "__main__": 17 main() 18 19----------------------------------------------------------------- 20実行結果 21Traceback (most recent call last): 22 File "get_business.py", line 26, in <module> 23 main() 24 File "get_business.py", line 13, in main 25 json_dict = json.loads(line) 26 File "C:\Users\user\AppData\Local\conda\conda\envs\anaconda\lib\json\__init__.py", line 354, in loads 27 return _default_decoder.decode(s) 28 File "C:\Users\user\AppData\Local\conda\conda\envs\anaconda\lib\json\decoder.py", line 342, in decode 29 raise JSONDecodeError("Extra data", s, end) 30json.decoder.JSONDecodeError: Extra data: line 1 column 1340 (char 1339) 31
business.txtは
{"business_id": "5UmKMjUEUNdYWqANhGckJw", "full_address": "4734 Lebanon Church Rd\nDravosburg, PA 15034", "hours": {"Friday": {"close": "21:00", "open": "11:00"}, "Tuesday": {"close": "21:00", "open": "11:00"}, "Thursday": {"close": "21:00", "open": "11:00"}, "Wednesday": {"close": "21:00", "open": "11:00"}, "Monday": {"close": "21:00", "open": "11:00"}}, "open": true, "categories": ["Fast Food", "Restaurants"], "city": "Dravosburg", "review_count": 7, "name": "Mr Hoagie", "neighborhoods": [], "longitude": -79.9007057, "state": "PA", "stars": 3.5, "latitude": 40.3543266, "attributes": {"Take-out": true, "Drive-Thru": false, "Good For": {"dessert": false, "latenight": false, "lunch": false, "dinner": false, "brunch": false, "breakfast": false}, "Caters": false, "Noise Level": "average", "Takes Reservations": false, "Delivery": false, "Ambience": {"romantic": false, "intimate": false, "classy": false, "hipster": false, "divey": false, "touristy": false, "trendy": false, "upscale": false, "casual": false}, "Parking": {"garage": false, "street": false, "validated": false, "lot": false, "valet": false}, "Has TV": false, "Outdoor Seating": false, "Attire": "casual", "Alcohol": "none", "Waiter Service": false, "Accepts Credit Cards": true, "Good for Kids": true, "Good For Groups": true, "Price Range": 1}, "type": "business"}{"business_id": "UsFtqoBl7naz8AVUBZMjQQ", "full_address": "202 McClure St\nDravosburg, PA 15034", "hours": {}, "open": true, "categories": ["Nightlife"], "city": "Dravosburg", "review_count": 5, "name": "Clancy's Pub", "neighborhoods": [], "longitude": -79.8868138, "state": "PA", "stars": 3.0, "latitude": 40.3505527, "attributes": {"Happy Hour": true, "Accepts Credit Cards": true, "Good For Groups": true, "Outdoor Seating": false, "Price Range": 1}, "type": "business"} {"business_id": "cE27W9VPgO88Qxe4ol6y_g", "full_address": "1530 Hamilton Rd\nBethel Park, PA 15234", "hours": {}, "open": false, "categories": ["Active Life", "Mini Golf", "Golf"], "city": "Bethel Park", "review_count": 5, "name": "Cool Springs Golf Center", "neighborhoods": [], "longitude": -80.0146597, "state": "PA", "stars": 2.5, "latitude": 40.3541155, "attributes": {"Good for Kids": true}, "type": "business"} {"business_id": "mVHrayjG3uZ_RLHkLj-AMg", "full_address": "414 Hawkins Ave\nBraddock, PA 15104", "hours": {"Tuesday": {"close": "19:00", "open": "10:00"}, "Friday": {"close": "20:00", "open": "10:00"}, "Wednesday": {"close": "19:00", "open": "10:00"}, "Thursday": {"close": "19:00", "open": "10:00"}, "Saturday": {"close": "16:00", "open": "10:00"}}, "open": true, "categories": ["Bars", "American (New)", "Nightlife", "Lounges", "Restaurants"], "city": "Braddock", "review_count": 26, "name": "Emil's Lounge", "neighborhoods": [], "longitude": -79.8662107, "state": "PA", "stars": 4.5, "latitude": 40.4088301, "attributes": {"Alcohol": "full_bar", "Noise Level": "average", "Has TV": true, "Attire": "casual", "Ambience": {"romantic": false, "intimate": false, "classy": false, "hipster": false, "divey": true, "touristy": false, "trendy": false, "upscale": false, "casual": false}, "Good for Kids": true, "Price Range": 2, "Good For Dancing": false, "Delivery": false, "Coat Check": false, "Smoking": "no", "Accepts Credit
このようなデータです
なぜエラーになるのでしょうか
追記
このデータだと実行することができます
python
1{"user_id": "ZxdojCZgZhw36xuSGaryRg", "text": "Pizza is garbage. Hoagies are excellent.", "business_id": "5UmKMjUEUNdYWqANhGckJw", "likes": 0, "date": "2016-07-17", "type": "tip"} 2{"user_id": "-6rEfobYjMxpUWLNxszaxQ", "text": "Don't waste your time.", "business_id": "cE27W9VPgO88Qxe4ol6y_g", "likes": 0, "date": "2013-04-18", "type": "tip"} 3{"user_id": "5OumCBQ_MyQsltSdbMyunA", "text": "Not easy to find. Be sure to put in directions for Rankin Police Department or you will end up at a residential home on the wrong Hawkins Ave. Found it after the third try. Also, it closes at 7pm.", "business_id": "mVHrayjG3uZ_RLHkLj-AMg", "likes": 0, "date": "2016-02-22", "type": "tip"} 4{"user_id": "EZ0r9dKKtEGVx2CdnowPCw", "text": "Your GPS will not allow you to find this place. Put Rankin police department in instead. They are directly across the street.", "business_id": "mVHrayjG3uZ_RLHkLj-AMg", "likes": 1, "date": "2013-01-06", "type": "tip"} 5{"user_id": "xb6zEQCw9I-Gl0g06e1KsQ", "text": "Great drink specials!", "business_id": "KayYbHCt-RkbGcPdGOThNg", "likes": 0, "date": "2013-12-03", "type": "tip"} 6
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/06/30 09:11
2017/06/30 10:27
2017/06/30 10:37