使用已编码的unicode对象加载json

时间:2018-09-03 05:27:58

标签: python json unicode

我有一个带有thease元素的json文件:

  

{“ created_at”:“星期日1月3日09:12:55 +0000   2016“,” id“:683576764392579072,” id_str“:” 683576764392579072“,” text“:” \ u067e \ u06cc \ u0627 \ u0645   \ u062a \ u0633 \ u0644 \ u06cc \ u062a \ u0631 \ u0626 \ u06cc \ u0633   \ u0645 \ u062c \ u0644 \ u0633 \ u062e \ u0628 \ u0631 \ u06af \ u0627 \ u0646   \ u062f \ u0631 \ u067e \ u06cc \ u0634 \ u0647 \ u0627 \ u062f \ u062a   \ u0634 \ u06cc \ u062e \ u0627 \ u0644 \ u0646 \ u0645 \ u0631   \ u007bshahrekhabar \ u007d https://t.co/ML75s9CTYX“,”源“:” \ u003ca   href = \“ http://ifttt.com \”   rel = \“ nofollow \” \ u003eIFTTT \ u003c / a \ u003e“,”截断“:false,” in_reply_to_status_id“:null,” in_reply_to_status_id_str“:null,” in_reply_to_user_id“:null,”:in_reply_to_user_id“:null,”:in_reply_to_user_id :null,“用户”:{“ id”:4678224625,“ id_str”:“ 4678224625”,“名称”:“胜利者”   病房”,“ screen_name”:“ victorward983”,“ location”:null,“ url”:null,“ description”:null,“ protected”:false,“ verified”:false,“ followers_count”:13,“ friends_count” :0,“ listed_count”:8,“ favourites_count”:0:“ statuses_count”:7262,“ created_at”:“ Wed Dec 30 13:21:18 +0000   2015“,” utc_offset“:null,” time_zone“:null,” geo_enabled“:false,” lang“:” en“,” contributors_enabled“:false,” is_translator“:false,” profile_background_color“:” F5F8FA“,” profile_background_image_url“:”“,” profile_background_image_url_https“:”“,” profile_background_tile“:false,” profile_link_color“:” 2B7BB9“,” profile_sidebar_border_color“:” C0DEED“,” profile_sidebar_fill_color“:” DDEEF6“,”“ profile_text_color ,“ profile_use_background_image”:true,“ profile_image_url”:“ http://pbs.twimg.com/profile_images/682190595184394240/0zFJDnmW_normal.jpg”,“ profile_image_url_https”:“ https://pbs.twimg.com/profile_images/682190595184394240/ 0zFJDnmW_normal.jpg“,” default_profile“:true,” default_profile_image“:false,”关注“:null,” follow_request_sent“:null,”通知“:null},” geo“:null,”坐标“:null,”地方“:null,”贡献者“:null,” is_quote_status“:false,” retweet_count“:0,” favorite_count“:0,” entities“:{” hashtags“:[],” urls“:[{” url“: “ https://t.co/ML75s9CTYX","expanded_url":"http://bit.ly/1W7F7X4","display_u rl“:” bit.ly/1W7F7X4","indices":[65,88]}],"user_mentions":[],"symbols":[]},"favorited":false,"reweeted":false, “ possible_sensitive”:false,“ filter_level”:“ low”,“ lang”:“ fa”,“ timestamp_ms”:“ 1451812375530”}

当我想用下面的代码加载它时:

aaa=f.read()
data = json.loads(aaa)
print(data)

python遇到此错误:

  

....引发JSONDecodeError(“额外数据”,s,结束)   json.decoder.JSONDecodeError:额外数据:第3行第1列(字符2208)

当我使用此代码时:

aaa=f.read()
data = json.loads(aaa.decode("utf-8"))
print(data)

它给了我这个错误:

  

AttributeError:'str'对象没有属性'decode'

如何加载带有解码的Unicode元素的json?

0 个答案:

没有答案
相关问题