python2.7でjsonloadsを使おうとすると
ValueError: No JSON object could be decoded
このようなエラーをはきます
python3.6をもともと使っていて
ちょっと2.7で動かす必要があって、2.7で動かそうとすると
エラーをはきます
python
1a = [] 2ful = open("tips.txt","r") 3 for line in ful: 4 json_dict = json.loads(line) 5 a.append([json_dict["user_id"],json_dict["business_id"],json_dict["text"]]) 6 ful.close() 7 8-------------------------------------------------------------- 9python3.6のときのコード 10 11a = [] 12ful = open("tips.txt","r",encoding='utf-8_sig') 13 for line in ful: 14 json_dict = json.loads(line) 15 a.append([json_dict["user_id"],json_dict["business_id"],json_dict["text"]]) 16 ful.close()
どうすればよいですか
-------追記---------
{"user_id": "ZxdojCZgZhw36xuSGaryRg", "text": "Pizza is garbage. Hoagies are excellent.", "business_id": "5UmKMjUEUNdYWqANhGckJw", "likes": 0, "date": "2016-07-17", "type": "tip"} {"user_id": "-6rEfobYjMxpUWLNxszaxQ", "text": "Don't waste your time.", "business_id": "cE27W9VPgO88Qxe4ol6y_g", "likes": 0, "date": "2013-04-18", "type": "tip"} {"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"} {"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"} {"user_id": "xb6zEQCw9I-Gl0g06e1KsQ", "text": "Great drink specials!", "business_id": "KayYbHCt-RkbGcPdGOThNg", "likes": 0, "date": "2013-12-03", "type": "tip"} {"user_id": "QawZN4PSW7ng_9SP7pjsVQ", "text": "Friendly staff, good food, great beer selection, and relaxing atmosphere", "business_id": "KayYbHCt-RkbGcPdGOThNg", "likes": 0, "date": "2015-07-08", "type": "tip"} {"user_id": "8K8qHAH9AREKxIIZAwQ9Fg", "text": "Fantastic! Great food, excellent beer selection! Bartenders are great!", "business_id": "KayYbHCt-RkbGcPdGOThNg", "likes": 0, "date": "2016-02-18", "type": "tip"}
このような行が10万行ほどあります
ただ、微妙にjsonと違うというか、表現しにくいのですが
理由あって、jsonloadではなく、jsonloadsで一行づつ読み込んでいます
-----さらに追記------
{"user_id": "ZxdojCZgZhw36xuSGaryRg"
id": "Zx の部分に空白があって、そこの部分でエラーがでているようです
ここを無視するようなコード等ありませんか
回答2件
あなたの回答
tips
プレビュー