Home > database >  json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 2167)
json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 2167)

Time:02-10

response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)
print(type(response.text))
print(json.loads(response.text))

Result

{"sku_id":"H7047001_S_24SM-2021130001B","primary_category_code":"AA31554520001","primary_category_name_en":"Gadgets & Electronics > Camera & Accessories > Camera Bag & Strap & Protector > Screen Protector","primary_category_name_chi":"大腦場 > 攝影器材 > 相機袋 相機帶 屏幕保護 > 屏幕保護","cat_codes":"AA31554520001","cat_names_en":"Gadgets & Electronics > Camera & Accessories > Camera Bag & Strap & Protector > Screen Protector","cat_names_chi":"大腦場 > 攝影器材 > 相機袋 相機帶 屏幕保護 > 屏幕保護","name_en":"iPhone 13 Pro Max tempered glass screen protector (suitable for iphone 13 )","name_chi":"iphone 13 Pro 鋼化保護貼(iphone 13 6.1通用)","brand_name_en":"hoco.","brand_name_chi":"hoco.","summary_en":"<p>1. PC nano edge, not broken edge<br/>2. The frame is higher than the glass surface to prevent the screen from breaking<br/>3. 3D arc edge<br/>4. Thickness 0.33mm<br/></p>","summary_chi":"<p>1,PC納米邊,不碎邊<br/>2,邊框高出玻璃面,防止摔碎屏幕<br/>3,3D弧邊<br/>4,厚度0.33mm<br/></p>","description_en":null,"description_chi":null,"image_urls":"https://cdn-mms.hktvmall.com/hktv/mms/uploadProductImage/c566/17e4/6c51/JmaqphYnzt20211130215445_1200.jpg | https://cdn-mms.hktvmall.com/hktv/mms/uploadProductImage/6f12/126c/4331/RyLUqftEEq20211130215435_1200.jpg | https://cdn-mms.hktvmall.com/hktv/mms/uploadProductImage/7820/ccd1/4779/AhlVGiJOgN20211130215443_1200.jpg","creation_time":"2021-11-30T21:57:23 08:00","store_code":"H7047001","original_price":99.0,"discount_price":49.000000500000006,"stock_available":5,"out_of_stock_since":null,"max_order_quantity":null,"total_shipped_quantity":null,"manu_country_en":"China","manu_country_chi":"中國","height":100.0,"length":50.0,"width":20.0,"dimension_unit":"mm","weight":0.1,"weight_unit":"kg","colors":null,"storage_type":"","packing_spec_en":"","packing_spec_chi":"","packing_box_type":"F","delivery_mode":"hktv-standard-delivery","pickup_days":"1/2/3/4/5/6","num_days_to_be_ready":0,"online_date":null,"offline_date":null,"loyalty_point":0.0,"shelf_life":0.0,"warranty_period":0,"warranty_period_unit":null,"warranty_supplier_en":null,"warranty_supplier_chi":null,"virtual_store_code":null,"virtual_store_name_en":null,"virtual_store_name_chi":null,"primary_store":"H7047001"}
{"sku_id":"H7047001_S_24SM-20210705002","primary_category_code":"AA73502030001","primary_category_name_en":"Sports & Travel > Outdoor Personal Cares > Sun Care > UV Shield Sun Sleeves","primary_category_name_chi":"運動旅行 > 戶外護理用品 > 防矖用品 > 防曬手袖","cat_codes":"AA73502030001","cat_names_en":"Sports & Travel > Outdoor Personal Cares > Sun Care > UV Shield Sun Sleeves","cat_names_chi":"運動旅行 > 戶外護理用品 > 防矖用品 > 防曬手袖","name_en":"MIT Children's Effective Cooling Mosquito Anti-UV Sleeve-American Eagle","name_chi":"『台灣製』兒童高效涼感防蚊抗UV袖套-美國鷹","brand_name_en":"24-LS","brand_name_chi":"24-LS","summary_en":"1. Add Tanatex EULAN natural and powerful anti-mosquito ingredients<br />2. SGS certified UPF50  effective sun protection!<br />3. The formaldehyde-free ingredients can be worn by children with peace of mind<br />4. Effectively avoid all kinds of mosquito bites<br />5. Ice ore coffee cool yarn material, cool to the touch and fast heat dissipation<br />6. Using Lycra elastic fiber, it fits snugly and is washable<br />7. Can be used as a foot cover","summary_chi":"1. 添加Tanatex EULAN類天然強效防蚊成分<br />2. SGS認證UPF50 有效防曬!<br />3. 無甲醛成份可以安心讓小朋友配帶<br />4. 有效避免各種蚊蟲叮咬<br />5. 冰礦咖啡涼感紗材質,觸感清涼,散熱快<br />6. 使用萊卡彈性纖維,服貼合身耐水洗<br />7.可當腳套","description_en":"Composition: 90% nylon (coffee yarn), 10% elastic fiber<br />. Specifications: Children's sleeves<br />. Size: Flat size: about 30CM long, arm width 7.5CM/maximum stretch: about 84CM long, 20CM arm width<br />. Origin: Taiwan","description_chi":"成分:尼龍90%(咖啡紗)、彈性纖維10%<br />.規格:兒童袖套<br />.尺寸:平量尺寸:約長30CM,臂寬7.5CM/最大拉伸:約長84CM,臂寬20CM<br />.產地:台灣","image_urls":"https://images.hktv-img.com/images/HKTV/23661/24SM-20210705002_main_67904340_20210705222213_01_1200.jpg","creation_time":"2021-07-05T15:20:00 08:00","store_code":"H7047001","original_price":99.0,"discount_price":59.0000004,"stock_available":1,"out_of_stock_since":null,"max_order_quantity":null,"total_shipped_quantity":2,"manu_country_en":"Taiwan","manu_country_chi":"台灣","height":80.0,"length":50.0,"width":20.0,"dimension_unit":"mm","weight":0.1,"weight_unit":"kg","colors":null,"storage_type":"","packing_spec_en":"","packing_spec_chi":"","packing_box_type":"H","delivery_mode":"hktv-standard-delivery","pickup_days":"1/2/3/4/5/6","num_days_to_be_ready":0,"online_date":null,"offline_date":"2099-01-01T00:00:00 08:00","loyalty_point":0.0,"shelf_life":0.0,"warranty_period":null,"warranty_period_unit":null,"warranty_supplier_en":null,"warranty_supplier_chi":null,"virtual_store_code":null,"virtual_store_name_en":null,"virtual_store_name_chi":null,"primary_store":"H7047001"}

<class 'str'>

json.decoder.JSONDecodeError: Extra data: line 2 column 1 (char 2167)

How can I solve this problem? I am stuck in json.loads.

I would like to put it into dictionary and then put it into dataframe and export into csv.

CodePudding user response:

it looks like you have two dictionaries in the response text, therefore you can do:

json_responses = response.text.split('\n')
for item in json_responses:
    if item != '':
        print(json.loads(item))

to load each of the dictionaries.

  • Related