@Brenli

Как изменить кодировку ответа от rest api woocommerce?

С помощью flask и скрипта на python получаю данные, но ответ выглядит следующим образом:

spoiler
[{"id":1053,"name":"\u041d\u0430\u043b\u0438\u0447\u043d\u0438\u043a 3D \u0412\u0435\u043d\u0433\u0435 \u0440\u0435\u043b\u044c\u0435\u0444\u043d\u044b\u0439","slug":"nalichnik-3d-venge-relefnyj","permalink":"https:\/\/site.ru.ru\/product\/nalichnik-3d-venge-relefnyj\/","date_created":"2017-02-08T16:07:38","date_created_gmt":"2017-02-08T11:07:38","date_modified":"2020-05-07T11:28:40","date_modified_gmt":"2020-05-07T06:28:40","type":"simple","status":"publish","featured":false,"catalog_visibility":"visible","description":"","short_description":"","sku":"17452","price":"135.00","regular_price":"135.00","sale_price":"","date_on_sale_from":null,"date_on_sale_from_gmt":null,"date_on_sale_to":null,"date_on_sale_to_gmt":null,"price_html":"135.00 р.<\/span><\/span>","on_sale":false,"purchasable":true,"total_sales":1,"virtual":false,"downloadable":false,"downloads":[],"download_limit":-1,"download_expiry":-1,"external_url":"","button_text":"","tax_status":"taxable","tax_class":"","manage_stock":false,"stock_quantity":null,"stock_status":"instock","backorders":"no","backorders_allowed":false,"backordered":false,"sold_individually":false,"weight":"","dimensions":{"length":"","width":"","height":""},"shipping_required":true,"shipping_taxable":true,"shipping_class":"","shipping_class_id":0,"reviews_allowed":true,"average_rating":"0.00","rating_count":0,"related_ids":[],"upsell_ids":[],"cross_sell_ids":[],"parent_id":0,"purchase_note":"","categories":[{"id":474,"name":"\u0422\u0435\u0441\u0442\u043e\u0432\u0430\u044f\u0414\u043e\u0447\u0435\u0440\u043d\u044f\u044f1","slug":"testovayadochernyaya1"}],"tags":[],"images":[{"id":364,"date_created":"2017-02-06T17:43:11","date_created_gmt":"2017-02-06T07:43:11","date_modified":"2017-02-06T17:43:11","date_modified_gmt":"2017-02-06T07:43:11","src":"https:\/\/site.ru.ru\/wp-content\/uploads\/2017\/02\/unavailable-3.jpg","name":"unavailable","alt":""}],"attributes":[],"default_attributes":[],"variations":[],"grouped_products":[],"menu_order":0,"meta_data":[],"_links":{"self":[{"href":"https:\/\/site.ru.ru\/wp-json\/wc\/v3\/products\/1053"}],"collection":[{"href":"https:\/\/site.ru\/wp-json\/wc\/v3\/products"}]}}]
  • Вопрос задан
  • 168 просмотров
Решения вопроса 1
hottabxp
@hottabxp Куратор тега Python
Сначала мы жили бедно, а потом нас обокрали..
Не совсем понятен вопрос, но могу предположить так:
import json

with open('json.txt') as file:
	json_data = json.loads(file.read())

print(json.dumps(json_data,ensure_ascii=False))

[{"id": 1053, "name": "Наличник 3D Венге рельефный", "slug": "nalichnik-3d-venge-relefnyj", "permalink": "https://site.ru.ru/product/nalichnik-3d-venge-relefnyj/", "date_created": "2017-02-08T16:07:38", "date_created_gmt": "2017-02-08T11:07:38", "date_modified": "2020-05-07T11:28:40", "date_modified_gmt": "2020-05-07T06:28:40", "type": "simple", "status": "publish", "featured": false, "catalog_visibility": "visible", "description": "", "short_description": "", "sku": "17452", "price": "135.00", "regular_price": "135.00", "sale_price": "", "date_on_sale_from": null, "date_on_sale_from_gmt": null, "date_on_sale_to": null, "date_on_sale_to_gmt": null, "price_html": "135.00 р.</span></span>", "on_sale": false, "purchasable": true, "total_sales": 1, "virtual": false, "downloadable": false, "downloads": [], "download_limit": -1, "download_expiry": -1, "external_url": "", "button_text": "", "tax_status": "taxable", "tax_class": "", "manage_stock": false, "stock_quantity": null, "stock_status": "instock", "backorders": "no", "backorders_allowed": false, "backordered": false, "sold_individually": false, "weight": "", "dimensions": {"length": "", "width": "", "height": ""}, "shipping_required": true, "shipping_taxable": true, "shipping_class": "", "shipping_class_id": 0, "reviews_allowed": true, "average_rating": "0.00", "rating_count": 0, "related_ids": [], "upsell_ids": [], "cross_sell_ids": [], "parent_id": 0, "purchase_note": "", "categories": [{"id": 474, "name": "ТестоваяДочерняя1", "slug": "testovayadochernyaya1"}], "tags": [], "images": [{"id": 364, "date_created": "2017-02-06T17:43:11", "date_created_gmt": "2017-02-06T07:43:11", "date_modified": "2017-02-06T17:43:11", "date_modified_gmt": "2017-02-06T07:43:11", "src": "https://site.ru.ru/wp-content/uploads/2017/02/unavailable-3.jpg", "name": "unavailable", "alt": ""}], "attributes": [], "default_attributes": [], "variations": [], "grouped_products": [], "menu_order": 0, "meta_data": [], "_links": {"self": [{"href": "https://site.ru.ru/wp-json/wc/v3/products/1053"}], "collection": [{"href": "https://site.ru/wp-json/wc/v3/products"}]}}]
Ответ написан
Пригласить эксперта
Ответы на вопрос 1
Вы смотрите на json кодированную строку
Прогоните ее через любой декодер json и получите удобочитаемые данные с декодированными символами
5ecbb9c91a0ed447313030.png
Ответ написан
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Похожие вопросы