{"id":77307,"date":"2024-08-29T17:14:34","date_gmt":"2024-08-29T10:14:34","guid":{"rendered":"https:\/\/itviec.com\/blog\/?p=77307"},"modified":"2024-08-29T17:14:34","modified_gmt":"2024-08-29T10:14:34","slug":"ung-dung-json-trong-python","status":"publish","type":"post","link":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/","title":{"rendered":"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON"},"content":{"rendered":"<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_84 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">N\u1ed9i dung b\u00e0i vi\u1ebft<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Cap_nhat_noi_dung_web\" >C\u1eadp nh\u1eadt n\u1ed9i dung web<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Logging\" >Logging<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Phat_trien_API\" >Ph\u00e1t tri\u1ec3n API<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Web_scraping\" >Web scraping<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Khi_nao_nen_su_dung_Flask_va_Khi_nao_nen_su_dung_Django\" >Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng Flask v\u00e0 Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng Django?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Cau_hoi_thuong_gap_ve_JSON_Python\" >C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 JSON Python<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#Tong_ket_JSON_Python_phan_2\" >T\u1ed5ng k\u1ebft JSON Python ph\u1ea7n 2<\/a><\/li><\/ul><\/nav><\/div>\n<p><em><strong>Sau khi \u0111\u00e3\u00a0n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON trong Python bao g\u1ed3m c\u00e1ch \u0111\u1ecdc v\u00e0 ghi d\u1eef li\u1ec7u, chuy\u1ec3n \u0111\u1ed5i gi\u1eefa c\u00e1c \u0111\u1ecbnh d\u1ea1ng d\u1eef li\u1ec7u v\u00e0 l\u01b0u tr\u1eef JSON, <\/strong><strong>b\u1ea1n s\u1ebd ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 nh\u1eefng \u1ee9ng d\u1ee5ng th\u1ef1c t\u1ebf c\u1ee7a JSON trong Python, gi\u00fap b\u1ea1n \u00e1p d\u1ee5ng nh\u1eefng ki\u1ebfn th\u1ee9c \u0111\u00e3 bi\u1ebft v\u00e0o c\u00e1c d\u1ef1 \u00e1n c\u1ee5 th\u1ec3.<\/strong><\/em><\/p>\n<p>\u1ede b\u00e0i vi\u1ebft <a href=\"https:\/\/itviec.com\/blog\/json-python-co-ban\/\" target=\"_blank\" rel=\"noopener\"><strong>JSON Python ph\u1ea7n 1: Thao t\u00e1c JSON c\u01a1 b\u1ea3n v\u1edbi Python<\/strong><\/a>, ch\u00fang ta \u0111\u00e3 \u0111i qua c\u00e1c ki\u1ebfn th\u1ee9c v\u1ec1:<\/p>\n<ul>\n<li>\u0110\u1ecdc file JSON<\/li>\n<li>Vi\u1ebft d\u1eef li\u1ec7u v\u00e0o file JSON<\/li>\n<li>Chuy\u1ec3n \u0111\u1ed5i t\u1eeb Python sang JSON<\/li>\n<li>L\u01b0u tr\u1eef JSON<\/li>\n<li>C\u00f4ng c\u1ee5 \u0111\u1ecbnh d\u1ea1ng JSON<\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">C\u00f2n \u1edf b\u00e0i vi\u1ebft n\u00e0y, b\u1ea1n s\u1ebd hi\u1ec3u r\u00f5 th\u00eam c\u00e1c \u1ee9ng d\u1ee5ng th\u1ef1c t\u1ebf c\u1ee7a JSON trong Python qua c\u00e1c ch\u1ee7 \u0111\u1ec1:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u1eadp nh\u1eadt n\u1ed9i dung web:<\/b><span style=\"font-weight: 400;\"> T\u1ef1 \u0111\u1ed9ng c\u1eadp nh\u1eadt th\u00f4ng tin tr\u00ean trang web t\u1eeb c\u00e1c ngu\u1ed3n d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ghi log:<\/b><span style=\"font-weight: 400;\"> S\u1eed d\u1ee5ng JSON \u0111\u1ec3 ghi log v\u00e0 theo d\u00f5i ho\u1ea1t \u0111\u1ed9ng c\u1ee7a \u1ee9ng d\u1ee5ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ph\u00e1t tri\u1ec3n API:<\/b><span style=\"font-weight: 400;\"> X\u00e2y d\u1ef1ng v\u00e0 tri\u1ec3n khai API s\u1eed d\u1ee5ng JSON \u0111\u1ec3 trao \u0111\u1ed5i d\u1eef li\u1ec7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Web scraping:<\/b><span style=\"font-weight: 400;\"> Thu th\u1eadp v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u t\u1eeb c\u00e1c trang web d\u01b0\u1edbi d\u1ea1ng JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ph\u00e1t tri\u1ec3n backend v\u1edbi Flask ho\u1eb7c Django:<\/b><span style=\"font-weight: 400;\"> Qu\u1ea3n l\u00fd v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u JSON trong c\u00e1c \u1ee9ng d\u1ee5ng web backend.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">B\u00e0i vi\u1ebft n\u00e0y d\u00e0nh cho nh\u1eefng l\u1eadp tr\u00ecnh vi\u00ean Python \u0111\u00e3 c\u00f3 ki\u1ebfn th\u1ee9c c\u0103n b\u1ea3n v\u00e0 nh\u1eefng ai \u0111ang s\u1eed d\u1ee5ng Python cho c\u00e1c c\u00f4ng vi\u1ec7c nh\u01b0 Data Engineering, Web Scraping, ho\u1eb7c ph\u00e1t tri\u1ec3n backend v\u1edbi c\u00e1c framework x\u1ecbn s\u00f2 nh\u01b0 Flask hay Django. H\u00e3y c\u00f9ng b\u1eaft \u0111\u1ea7u h\u00e0nh tr\u00ecnh kh\u00e1m ph\u00e1 JSON v\u1edbi Python n\u00e0o!<\/span><\/p>\n<blockquote><p><em>\u0110\u1ecdc th\u00eam: <a href=\"https:\/\/itviec.com\/blog\/json-la-gi\/\" target=\"_blank\" rel=\"noopener\"><strong>JSON l\u00e0 g\u00ec? C\u00e1c lo\u1ea1i d\u1eef li\u1ec7u JSON l\u00e0 g\u00ec v\u00e0 \u00e1p d\u1ee5ng th\u1ebf n\u00e0o?<\/strong><\/a><\/em><\/p><\/blockquote>\n<h2><span class=\"ez-toc-section\" id=\"Cap_nhat_noi_dung_web\"><\/span><strong>C\u1eadp nh\u1eadt n\u1ed9i dung web<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Trong th\u1eddi \u0111\u1ea1i s\u1ed1 h\u00f3a hi\u1ec7n nay, vi\u1ec7c c\u1eadp nh\u1eadt n\u1ed9i dung web m\u1ed9t c\u00e1ch t\u1ef1 \u0111\u1ed9ng l\u00e0 \u0111i\u1ec1u c\u1ea7n thi\u1ebft \u0111\u1ec3 gi\u1eef cho trang web c\u1ee7a b\u1ea1n lu\u00f4n m\u1edbi m\u1ebb v\u00e0 h\u1ea5p d\u1eabn. Python, v\u1edbi c\u00e1c th\u01b0 vi\u1ec7n m\u1ea1nh m\u1ebd nh\u01b0 <\/span><span style=\"font-weight: 400;\">requests<\/span><span style=\"font-weight: 400;\"> v\u00e0 <\/span><span style=\"font-weight: 400;\">BeautifulSoup<\/span><span style=\"font-weight: 400;\">, cho ph\u00e9p b\u1ea1n d\u1ec5 d\u00e0ng l\u1ea5y d\u1eef li\u1ec7u t\u1eeb c\u00e1c ngu\u1ed3n kh\u00e1c nhau v\u00e0 c\u1eadp nh\u1eadt n\u1ed9i dung web.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">V\u00ed d\u1ee5, b\u1ea1n c\u00f3 th\u1ec3 l\u1ea5y th\u00f4ng tin th\u1eddi ti\u1ebft t\u1eeb m\u1ed9t API v\u00e0 hi\u1ec3n th\u1ecb n\u00f3 tr\u00ean trang web c\u1ee7a m\u00ecnh:<\/span><\/p>\n<pre>import requests\r\nimport json\r\n\r\nurl = \"https:\/\/api.weatherapi.com\/v1\/current.json?key=YOUR_API_KEY&amp;q=London\"\r\nresponse = requests.get(url)\r\nweather_data = response.json()\r\n\r\n# Gi\u1ea3 s\u1eed b\u1ea1n c\u00f3 m\u1ed9t h\u00e0m update_web_content() \u0111\u1ec3 c\u1eadp nh\u1eadt n\u1ed9i dung web\r\nupdate_web_content(weather_data)<\/pre>\n<p><span style=\"font-weight: 400;\">B\u1ea1n c\u00f3 th\u1ec3 tham kh\u1ea3o chi ti\u1ebft c\u00e1ch t\u1ea1o m\u1ed9t app th\u1eddi ti\u1ebft b\u1eb1ng video sau: <\/span><a href=\"https:\/\/www.youtube.com\/watch?v=8e1D4msEYus\"><span style=\"font-weight: 400;\">Build a Weather App with JavaScript &amp; WeatherAPI.com | Step-by-Step Tutorial<\/span><\/a><\/p>\n<p><b>Gi\u1ea3i th\u00edch code<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import requests<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n requests d\u00f9ng \u0111\u1ec3 g\u1eedi y\u00eau c\u1ea7u HTTP.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import json<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n json d\u00f9ng \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>url=&#8221;https:\/\/api.weatherapi.com\/v1\/current.json?key=YOUR_API_KEY&amp;q=London&#8221;<\/strong><span style=\"font-weight: 400;\">: \u0110\u1eb7t URL c\u1ee7a API cung c\u1ea5p th\u00f4ng tin th\u1eddi ti\u1ebft.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>response = requests.get(url)<\/strong><span style=\"font-weight: 400;\">: G\u1eedi y\u00eau c\u1ea7u GET t\u1edbi API v\u00e0 nh\u1eadn ph\u1ea3n h\u1ed3i.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>weather_data = response.json()<\/strong><span style=\"font-weight: 400;\">: Chuy\u1ec3n \u0111\u1ed5i ph\u1ea3n h\u1ed3i JSON th\u00e0nh \u0111\u1ed1i t\u01b0\u1ee3ng Python.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>update_web_content(weather_data)<\/strong><span style=\"font-weight: 400;\">: H\u00e0m gi\u1ea3 \u0111\u1ecbnh \u0111\u1ec3 c\u1eadp nh\u1eadt n\u1ed9i dung web v\u1edbi d\u1eef li\u1ec7u th\u1eddi ti\u1ebft.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Logging\"><\/span><b>Logging<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Ghi log l\u00e0 m\u1ed9t ph\u1ea7n kh\u00f4ng th\u1ec3 thi\u1ebfu trong qu\u00e1 tr\u00ecnh ph\u00e1t tri\u1ec3n v\u00e0 v\u1eadn h\u00e0nh \u1ee9ng d\u1ee5ng. Python cung c\u1ea5p module <\/span><span style=\"font-weight: 400;\">logging<\/span><span style=\"font-weight: 400;\"> t\u00edch h\u1ee3p s\u1eb5n, cho ph\u00e9p b\u1ea1n ghi log d\u01b0\u1edbi d\u1ea1ng JSON. \u0110i\u1ec1u n\u00e0y gi\u00fap b\u1ea1n d\u1ec5 d\u00e0ng l\u01b0u tr\u1eef v\u00e0 ph\u00e2n t\u00edch log:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> logging<\/span>\r\n<span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> json_log_formatter<\/span>\r\n\r\n<span style=\"font-weight: 400;\">formatter = json_log_formatter.JSONFormatter()<\/span>\r\n<span style=\"font-weight: 400;\">json_handler = logging.FileHandler(filename=<\/span><span style=\"font-weight: 400;\">'app.log'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">json_handler.setFormatter(formatter)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">logger = logging.getLogger(<\/span><span style=\"font-weight: 400;\">'my_json_logger'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">logger.addHandler(json_handler)<\/span>\r\n<span style=\"font-weight: 400;\">logger.setLevel(logging.INFO)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">logger.info(<\/span><span style=\"font-weight: 400;\">\"Application started\"<\/span><span style=\"font-weight: 400;\">, extra={<\/span><span style=\"font-weight: 400;\">\"key\"<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">\"value\"<\/span><span style=\"font-weight: 400;\">})<\/span><\/pre>\n<p><b>Gi\u1ea3i th\u00edch code<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import logging<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n logging d\u00f9ng \u0111\u1ec3 ghi log.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import json_log_formatter<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n json_log_formatter \u0111\u1ec3 \u0111\u1ecbnh d\u1ea1ng log d\u01b0\u1edbi d\u1ea1ng JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>formatter = json_log_formatter.JSONFormatter()<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o formatter \u0111\u1ec3 \u0111\u1ecbnh d\u1ea1ng log th\u00e0nh JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>json_handler = logging.FileHandler(filename=&#8217;app.log&#8217;)<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o handler \u0111\u1ec3 ghi log v\u00e0o file <\/span><span style=\"font-weight: 400;\">app.log<\/span><span style=\"font-weight: 400;\">.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>json_handler.setFormatter(formatter)<\/strong><span style=\"font-weight: 400;\">: \u0110\u1eb7t formatter cho handler.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>logger = logging.getLogger(&#8216;my_json_logger&#8217;)<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o logger v\u1edbi t\u00ean &#8216;my_json_logger&#8217;.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>logger.addHandler(json_handler)<\/strong><span style=\"font-weight: 400;\">: Th\u00eam handler v\u00e0o logger.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>logger.setLevel(logging.INFO)<\/strong><span style=\"font-weight: 400;\">: \u0110\u1eb7t m\u1ee9c log l\u00e0 INFO.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>logger.info(&#8220;Application started&#8221;, extra={&#8220;key&#8221;: &#8220;value&#8221;})<\/strong><span style=\"font-weight: 400;\">: Ghi log th\u00f4ng tin v\u1edbi message v\u00e0 d\u1eef li\u1ec7u b\u1ed5 sung.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Phat_trien_API\"><\/span><b>Ph\u00e1t tri\u1ec3n API<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Ph\u00e1t tri\u1ec3n API l\u00e0 m\u1ed9t trong nh\u1eefng \u1ee9ng d\u1ee5ng ph\u1ed5 bi\u1ebfn c\u1ee7a Python trong vi\u1ec7c x\u1eed l\u00fd JSON. S\u1eed d\u1ee5ng c\u00e1c framework nh\u01b0 Flask hay Django, b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng x\u00e2y d\u1ef1ng v\u00e0 tri\u1ec3n khai c\u00e1c API \u0111\u1ec3 trao \u0111\u1ed5i d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng JSON.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">D\u01b0\u1edbi \u0111\u00e2y l\u00e0 v\u00ed d\u1ee5 \u0111\u01a1n gi\u1ea3n v\u1edbi Flask:<\/span><\/p>\n<pre>from flask import Flask, jsonify, request\r\n\r\napp = Flask(__name__)\r\n\r\n@app.route('\/api\/data', methods=['GET'])\r\ndef get_data():\r\n\u00a0 \u00a0 data = {\"message\": \"Hello, world!\"}\r\n\u00a0 \u00a0 return jsonify(data)\r\n\r\n@app.route('\/api\/data', methods=['POST'])\r\ndef post_data():\r\n\u00a0 \u00a0 new_data = request.get_json()\r\n\u00a0 \u00a0 return jsonify(new_data), 201\r\n\r\nif __name__ == '__main__':\r\n\u00a0 \u00a0 app.run(debug=True)<\/pre>\n<p><b>Gi\u1ea3i th\u00edch code<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>from flask import Flask, jsonify, request<\/strong><span style=\"font-weight: 400;\">: Import c\u00e1c module c\u1ea7n thi\u1ebft t\u1eeb Flask.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>app = Flask(__name__)<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o m\u1ed9t \u1ee9ng d\u1ee5ng Flask.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>@app.route(&#8216;\/api\/data&#8217;, methods=[&#8216;GET&#8217;])<\/strong><span style=\"font-weight: 400;\">: \u0110\u1ecbnh ngh\u0129a route cho ph\u01b0\u01a1ng th\u1ee9c GET.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>def get_data()<\/strong><span style=\"font-weight: 400;\">: H\u00e0m x\u1eed l\u00fd y\u00eau c\u1ea7u GET.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>data = {&#8220;message&#8221;: &#8220;Hello, world!&#8221;}<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o d\u1eef li\u1ec7u JSON \u0111\u1ec3 tr\u1ea3 v\u1ec1.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>return jsonify(data)<\/strong><span style=\"font-weight: 400;\">: Tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u d\u01b0\u1edbi d\u1ea1ng JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>@app.route(&#8216;\/api\/data&#8217;, methods=[&#8216;POST&#8217;])<\/strong><span style=\"font-weight: 400;\">: \u0110\u1ecbnh ngh\u0129a route cho ph\u01b0\u01a1ng th\u1ee9c POST.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>def post_data()<\/strong><span style=\"font-weight: 400;\">: H\u00e0m x\u1eed l\u00fd y\u00eau c\u1ea7u POST.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>new_data = request.get_json()<\/strong><span style=\"font-weight: 400;\">: L\u1ea5y d\u1eef li\u1ec7u JSON t\u1eeb y\u00eau c\u1ea7u POST.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>return jsonify(new_data), 201<\/strong><span style=\"font-weight: 400;\">: Tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u m\u1edbi v\u1edbi m\u00e3 tr\u1ea1ng th\u00e1i 201 (Created).<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>if __name__ == &#8216;__main__&#8217;: app.run(debug=True)<\/strong><span style=\"font-weight: 400;\">: Ch\u1ea1y \u1ee9ng d\u1ee5ng Flask \u1edf ch\u1ebf \u0111\u1ed9 debug.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Web_scraping\"><\/span><b>Web scraping<\/b><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Web scraping l\u00e0 k\u1ef9 thu\u1eadt thu th\u1eadp d\u1eef li\u1ec7u t\u1eeb c\u00e1c trang web. V\u1edbi Python v\u00e0 th\u01b0 vi\u1ec7n <\/span><span style=\"font-weight: 400;\">BeautifulSoup<\/span><span style=\"font-weight: 400;\">, b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng l\u1ea5y d\u1eef li\u1ec7u v\u00e0 chuy\u1ec3n \u0111\u1ed5i n\u00f3 th\u00e0nh JSON \u0111\u1ec3 l\u01b0u tr\u1eef ho\u1eb7c x\u1eed l\u00fd th\u00eam:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> requests<\/span>\r\n<span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> bs4 <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> BeautifulSoup<\/span>\r\n<span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> json<\/span>\r\n\r\n<span style=\"font-weight: 400;\">url = <\/span><span style=\"font-weight: 400;\">'https:\/\/example.com'<\/span>\r\n<span style=\"font-weight: 400;\">response = requests.get(url)<\/span>\r\n<span style=\"font-weight: 400;\">soup = BeautifulSoup(response.content, <\/span><span style=\"font-weight: 400;\">'html.parser'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">data = {<\/span><span style=\"font-weight: 400;\">\"title\"<\/span><span style=\"font-weight: 400;\">: soup.title.string}<\/span>\r\n<span style=\"font-weight: 400;\">print(json.dumps(data, indent=<\/span><span style=\"font-weight: 400;\">4<\/span><span style=\"font-weight: 400;\">))<\/span><\/pre>\n<p><span style=\"font-weight: 400;\">H\u00ecnh n\u00e0y l\u00e0 m\u1ed9t v\u00ed d\u1ee5 khi b\u1ea1n c\u1ea7n l\u1ea5y c\u00e1c n\u1ed9i dung tr\u00ean m\u1ed9t website. Web scraping l\u00e0 m\u1ed9t k\u1ef9 n\u0103ng ph\u1ee9c t\u1ea1p v\u00e0 c\u00f3 nhi\u1ec1u k\u1ef9 thu\u1eadt kh\u00e1c nhau cho m\u1ed7i trang web kh\u00e1c nhau. \u0110\u00f4i khi y\u1ebfu t\u1ed1 \u0111\u1ea1o \u0111\u1ee9c v\u00e0 s\u1edf h\u1eefu tr\u00ed tu\u1ec7 c\u0169ng l\u00e0 \u0111i\u1ec1u m\u00e0 b\u1ea1n n\u00ean c\u00e2n nh\u1eafc khi d\u00f9ng k\u1ef9 thu\u1eadt n\u00e0y v\u00ec b\u1ea1n c\u00f3 th\u1ec3 g\u1eb7p ph\u1ea3i nh\u1eefng r\u1ee7i ro ph\u00e1p l\u00fd.<\/span><\/p>\n<p><b>Gi\u1ea3i th\u00edch code<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import requests<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n requests \u0111\u1ec3 g\u1eedi y\u00eau c\u1ea7u HTTP.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>from bs4 import BeautifulSoup<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n BeautifulSoup \u0111\u1ec3 ph\u00e2n t\u00edch c\u00fa ph\u00e1p HTML.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import json<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n json \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>url = &#8216;https:\/\/example.com&#8217;<\/strong><span style=\"font-weight: 400;\">: \u0110\u1eb7t URL c\u1ee7a trang web c\u1ea7n scraping.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>response = requests.get(url)<\/strong><span style=\"font-weight: 400;\">: G\u1eedi y\u00eau c\u1ea7u GET t\u1edbi trang web.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>soup = BeautifulSoup(response.content, &#8216;html.parser&#8217;)<\/strong><span style=\"font-weight: 400;\">: Ph\u00e2n t\u00edch n\u1ed9i dung HTML c\u1ee7a trang web.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>data = {&#8220;title&#8221;: soup.title.string}<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng JSON v\u1edbi ti\u00eau \u0111\u1ec1 trang web.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>print(json.dumps(data, indent=4))<\/strong><span style=\"font-weight: 400;\">: In d\u1eef li\u1ec7u JSON v\u1edbi \u0111\u1ecbnh d\u1ea1ng \u0111\u1eb9p.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Khi_nao_nen_su_dung_Flask_va_Khi_nao_nen_su_dung_Django\"><\/span>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng Flask v\u00e0 Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng Django?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">Python kh\u00f4ng ch\u1ec9 m\u1ea1nh m\u1ebd trong vi\u1ec7c ph\u00e1t tri\u1ec3n API m\u00e0 c\u00f2n c\u1ef1c k\u1ef3 hi\u1ec7u qu\u1ea3 trong vi\u1ec7c x\u00e2y d\u1ef1ng backend cho c\u00e1c \u1ee9ng d\u1ee5ng web. Flask v\u00e0 Django l\u00e0 hai framework ph\u1ed5 bi\u1ebfn nh\u1ea5t gi\u00fap b\u1ea1n d\u1ec5 d\u00e0ng qu\u1ea3n l\u00fd d\u1eef li\u1ec7u JSON trong c\u00e1c \u1ee9ng d\u1ee5ng c\u1ee7a m\u00ecnh.<\/span><\/p>\n<h3><b>Flask<\/b><\/h3>\n<p>N\u00ean s\u1eed d\u1ee5ng Flask khi:<\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>D\u1ef1 \u00e1n nh\u1ecf v\u00e0 \u0111\u01a1n gi\u1ea3n<\/b><span style=\"font-weight: 400;\">: Flask ph\u00f9 h\u1ee3p v\u1edbi c\u00e1c d\u1ef1 \u00e1n nh\u1ecf, y\u00eau c\u1ea7u \u0111\u01a1n gi\u1ea3n v\u00e0 kh\u00f4ng c\u1ea7n nhi\u1ec1u t\u00ednh n\u0103ng ph\u1ee9c t\u1ea1p. V\u00ed d\u1ee5, m\u1ed9t API nh\u1ecf ho\u1eb7c m\u1ed9t \u1ee9ng d\u1ee5ng web \u0111\u01a1n gi\u1ea3n c\u00f3 th\u1ec3 \u0111\u01b0\u1ee3c x\u00e2y d\u1ef1ng nhanh ch\u00f3ng v\u1edbi Flask.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Ki\u1ec3m so\u00e1t linh ho\u1ea1t<\/b><span style=\"font-weight: 400;\">: Flask cung c\u1ea5p s\u1ef1 linh ho\u1ea1t cao, cho ph\u00e9p l\u1eadp tr\u00ecnh vi\u00ean t\u1ef1 do l\u1ef1a ch\u1ecdn c\u00e1c th\u00e0nh ph\u1ea7n v\u00e0 c\u00f4ng c\u1ee5 kh\u00e1c \u0111\u1ec3 x\u00e2y d\u1ef1ng \u1ee9ng d\u1ee5ng. \u0110i\u1ec1u n\u00e0y h\u1eefu \u00edch khi b\u1ea1n c\u1ea7n t\u00f9y ch\u1ec9nh nhi\u1ec1u v\u00e0 kh\u00f4ng mu\u1ed1n b\u1ecb r\u00e0ng bu\u1ed9c b\u1edfi m\u1ed9t framework c\u1ed1 \u0111\u1ecbnh.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00ecm hi\u1ec3u v\u00e0 h\u1ecdc t\u1eadp<\/b><span style=\"font-weight: 400;\">: Flask c\u00f3 c\u00fa ph\u00e1p \u0111\u01a1n gi\u1ea3n v\u00e0 d\u1ec5 h\u1ecdc, l\u00e0 m\u1ed9t l\u1ef1a ch\u1ecdn t\u1ed1t cho ng\u01b0\u1eddi m\u1edbi b\u1eaft \u0111\u1ea7u h\u1ecdc v\u1ec1 l\u1eadp tr\u00ecnh web v\u00e0 x\u00e2y d\u1ef1ng API.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">V\u1edbi Flask, b\u1ea1n c\u00f3 th\u1ec3 d\u1ec5 d\u00e0ng x\u1eed l\u00fd c\u00e1c y\u00eau c\u1ea7u JSON v\u00e0 tr\u1ea3 v\u1ec1 k\u1ebft qu\u1ea3 d\u01b0\u1edbi d\u1ea1ng JSON:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> flask <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> Flask, request, jsonify<\/span>\r\n\r\n<span style=\"font-weight: 400;\">app = Flask(__name__)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">@app.route('\/json', methods=['POST'])<\/span>\r\n<span style=\"font-weight: 400;\">def<\/span><span style=\"font-weight: 400;\"> json_example<\/span><span style=\"font-weight: 400;\">()<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 request_data = request.get_json()<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 name = request_data.get(<\/span><span style=\"font-weight: 400;\">'name'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 age = request_data.get(<\/span><span style=\"font-weight: 400;\">'age'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 response = {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\"message\"<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">f\"Hello <\/span><span style=\"font-weight: 400;\">{name}<\/span><span style=\"font-weight: 400;\">, you are <\/span><span style=\"font-weight: 400;\">{age}<\/span><span style=\"font-weight: 400;\"> years old!\"<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> jsonify(response)<\/span>\r\n\r\n<span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> __name__ == <\/span><span style=\"font-weight: 400;\">'__main__'<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 app.run(debug=<\/span><span style=\"font-weight: 400;\">True<\/span><span style=\"font-weight: 400;\">)<\/span><\/pre>\n<p><b>Gi\u1ea3i th\u00edch code<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>from flask import Flask, request, jsonify<\/strong><span style=\"font-weight: 400;\">: Import c\u00e1c module c\u1ea7n thi\u1ebft t\u1eeb Flask.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>app = Flask(__name__)<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o m\u1ed9t \u1ee9ng d\u1ee5ng Flask.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>@app.route(&#8216;\/json&#8217;, methods=[&#8216;POST&#8217;])<\/strong><span style=\"font-weight: 400;\">: \u0110\u1ecbnh ngh\u0129a route cho ph\u01b0\u01a1ng th\u1ee9c POST.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>def json_example()<\/strong><span style=\"font-weight: 400;\">: H\u00e0m x\u1eed l\u00fd y\u00eau c\u1ea7u POST.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>request_data = request.get_json()<\/strong><span style=\"font-weight: 400;\">: L\u1ea5y d\u1eef li\u1ec7u JSON t\u1eeb y\u00eau c\u1ea7u POST.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>name = request_data.get(&#8216;name&#8217;)<\/strong><span style=\"font-weight: 400;\">: L\u1ea5y gi\u00e1 tr\u1ecb &#8216;name&#8217; t\u1eeb d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>age = request_data.get(&#8216;age&#8217;)<\/strong><span style=\"font-weight: 400;\">: L\u1ea5y gi\u00e1 tr\u1ecb &#8216;age&#8217; t\u1eeb d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>response = {&#8220;message&#8221;: f&#8221;Hello {name}, you are {age} years old!&#8221;}<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng JSON \u0111\u1ec3 tr\u1ea3 v\u1ec1.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>return jsonify(response)<\/strong><span style=\"font-weight: 400;\">: Tr\u1ea3 v\u1ec1 \u0111\u1ed1i t\u01b0\u1ee3ng JSON.<\/span><\/li>\n<\/ul>\n<h3><strong>Django<\/strong><\/h3>\n<p>N\u00ean s\u1eed d\u1ee5ng Django khi:<\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>D\u1ef1 \u00e1n l\u1edbn v\u00e0 ph\u1ee9c t\u1ea1p<\/b><span style=\"font-weight: 400;\">: Django th\u00edch h\u1ee3p cho c\u00e1c d\u1ef1 \u00e1n l\u1edbn h\u01a1n, y\u00eau c\u1ea7u nhi\u1ec1u t\u00ednh n\u0103ng v\u00e0 c\u1ea7n m\u1ed9t c\u1ea5u tr\u00fac m\u1ea1nh m\u1ebd. V\u00ed d\u1ee5, c\u00e1c \u1ee9ng d\u1ee5ng th\u01b0\u01a1ng m\u1ea1i \u0111i\u1ec7n t\u1eed, m\u1ea1ng x\u00e3 h\u1ed9i, ho\u1eb7c h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd n\u1ed9i dung.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>T\u00edch h\u1ee3p s\u1eb5n nhi\u1ec1u t\u00ednh n\u0103ng<\/b><span style=\"font-weight: 400;\">: Django \u0111i k\u00e8m v\u1edbi nhi\u1ec1u t\u00ednh n\u0103ng t\u00edch h\u1ee3p nh\u01b0 ORM (Object-Relational Mapping), h\u1ec7 th\u1ed1ng qu\u1ea3n l\u00fd ng\u01b0\u1eddi d\u00f9ng, v\u00e0 c\u00e1c c\u00f4ng c\u1ee5 b\u1ea3o m\u1eadt. \u0110i\u1ec1u n\u00e0y gi\u00fap b\u1ea1n ti\u1ebft ki\u1ec7m th\u1eddi gian ph\u00e1t tri\u1ec3n v\u00e0 \u0111\u1ea3m b\u1ea3o c\u00e1c ti\u00eau chu\u1ea9n b\u1ea3o m\u1eadt.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Qu\u1ea3n l\u00fd v\u00e0 b\u1ea3o tr\u00ec d\u1ec5 d\u00e0ng<\/b><span style=\"font-weight: 400;\">: V\u1edbi Django, b\u1ea1n c\u00f3 m\u1ed9t c\u1ea5u tr\u00fac d\u1ef1 \u00e1n r\u00f5 r\u00e0ng v\u00e0 qu\u1ea3n l\u00fd d\u1ec5 d\u00e0ng h\u01a1n, \u0111\u1eb7c bi\u1ec7t l\u00e0 khi l\u00e0m vi\u1ec7c trong c\u00e1c nh\u00f3m ph\u00e1t tri\u1ec3n l\u1edbn.<\/span><\/li>\n<\/ul>\n<p><span style=\"font-weight: 400;\">Django c\u0169ng h\u1ed7 tr\u1ee3 m\u1ea1nh m\u1ebd vi\u1ec7c x\u1eed l\u00fd JSON v\u1edbi REST framework, gi\u00fap b\u1ea1n x\u00e2y d\u1ef1ng c\u00e1c \u1ee9ng d\u1ee5ng web ph\u1ee9c t\u1ea1p h\u01a1n:<\/span><\/p>\n<pre><span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> django.http <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> JsonResponse<\/span>\r\n<span style=\"font-weight: 400;\">from<\/span><span style=\"font-weight: 400;\"> django.views.decorators.csrf <\/span><span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> csrf_exempt<\/span>\r\n<span style=\"font-weight: 400;\">import<\/span><span style=\"font-weight: 400;\"> json<\/span>\r\n\r\n<span style=\"font-weight: 400;\">@csrf_exempt<\/span>\r\n<span style=\"font-weight: 400;\">def<\/span><span style=\"font-weight: 400;\"> json_example<\/span><span style=\"font-weight: 400;\">(request)<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">if<\/span><span style=\"font-weight: 400;\"> request.method == <\/span><span style=\"font-weight: 400;\">'POST'<\/span><span style=\"font-weight: 400;\">:<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 data = json.loads(request.body)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 name = data.get(<\/span><span style=\"font-weight: 400;\">'name'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 age = data.get(<\/span><span style=\"font-weight: 400;\">'age'<\/span><span style=\"font-weight: 400;\">)<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 response = {<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">\"message\"<\/span><span style=\"font-weight: 400;\">: <\/span><span style=\"font-weight: 400;\">f\"Hello <\/span><span style=\"font-weight: 400;\">{name}<\/span><span style=\"font-weight: 400;\">, you are <\/span><span style=\"font-weight: 400;\">{age}<\/span><span style=\"font-weight: 400;\"> years old!\"<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 }<\/span>\r\n<span style=\"font-weight: 400;\">\u00a0 \u00a0 \u00a0 \u00a0 <\/span><span style=\"font-weight: 400;\">return<\/span><span style=\"font-weight: 400;\"> JsonResponse(response)<\/span><\/pre>\n<p><b>Gi\u1ea3i th\u00edch code<\/b><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>from django.http import JsonResponse<\/strong><span style=\"font-weight: 400;\">: Import JsonResponse t\u1eeb Django \u0111\u1ec3 tr\u1ea3 v\u1ec1 d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>from django.views.decorators.csrf import csrf_exempt<\/strong><span style=\"font-weight: 400;\">: Import csrf_exempt \u0111\u1ec3 b\u1ecf qua ki\u1ec3m tra CSRF.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>import json<\/strong><span style=\"font-weight: 400;\">: Th\u01b0 vi\u1ec7n json \u0111\u1ec3 x\u1eed l\u00fd d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>@csrf_exempt<\/strong><span style=\"font-weight: 400;\">: \u0110\u1eb7t decorator \u0111\u1ec3 b\u1ecf qua ki\u1ec3m tra CSRF.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>def json_example(request)<\/strong><span style=\"font-weight: 400;\">: \u0110\u1ecbnh ngh\u0129a h\u00e0m x\u1eed l\u00fd y\u00eau c\u1ea7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>if request.method == &#8216;POST&#8217;: data = json.loads(request.body)<\/strong><span style=\"font-weight: 400;\">: Ki\u1ec3m tra n\u1ebfu ph\u01b0\u01a1ng th\u1ee9c l\u00e0 POST v\u00e0 \u0111\u1ecdc d\u1eef li\u1ec7u JSON t\u1eeb y\u00eau c\u1ea7u.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>name = data.get(&#8216;name&#8217;)<\/strong><span style=\"font-weight: 400;\">: L\u1ea5y gi\u00e1 tr\u1ecb &#8216;name&#8217; t\u1eeb d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>age = data.get(&#8216;age&#8217;)<\/strong><span style=\"font-weight: 400;\">: L\u1ea5y gi\u00e1 tr\u1ecb &#8216;age&#8217; t\u1eeb d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>response = {&#8220;message&#8221;: f&#8221;Hello {name}, you are {age} years old!&#8221;}<\/strong><span style=\"font-weight: 400;\">: T\u1ea1o \u0111\u1ed1i t\u01b0\u1ee3ng JSON \u0111\u1ec3 tr\u1ea3 v\u1ec1.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><strong>return JsonResponse(response)<\/strong><span style=\"font-weight: 400;\">: Tr\u1ea3 v\u1ec1 \u0111\u1ed1i t\u01b0\u1ee3ng JSON.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Cau_hoi_thuong_gap_ve_JSON_Python\"><\/span><strong>C\u00e2u h\u1ecfi th\u01b0\u1eddng g\u1eb7p v\u1ec1 JSON Python<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<h3><strong>Khi n\u00e0o n\u00ean s\u1eed d\u1ee5ng JSON thay v\u00ec XML?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">JSON n\u00ean \u0111\u01b0\u1ee3c s\u1eed d\u1ee5ng thay v\u00ec XML khi b\u1ea1n c\u1ea7n m\u1ed9t \u0111\u1ecbnh d\u1ea1ng d\u1eef li\u1ec7u d\u1ec5 \u0111\u1ecdc v\u00e0 vi\u1ebft, nh\u1eb9 v\u00e0 c\u00f3 th\u1ec3 t\u00edch h\u1ee3p t\u1ed1t v\u1edbi c\u00e1c ng\u00f4n ng\u1eef l\u1eadp tr\u00ecnh hi\u1ec7n \u0111\u1ea1i. JSON c\u0169ng th\u00edch h\u1ee3p cho vi\u1ec7c truy\u1ec1n d\u1eef li\u1ec7u qua m\u1ea1ng v\u00ec k\u00edch th\u01b0\u1edbc nh\u1ecf h\u01a1n so v\u1edbi XML.<\/span><\/p>\n<p><span style=\"font-weight: 400;\">Tuy nhi\u00ean, n\u1ebfu b\u1ea1n c\u1ea7n c\u1ea5u tr\u00fac d\u1eef li\u1ec7u ph\u1ee9c t\u1ea1p v\u1edbi c\u00e1c \u0111\u1eb7c \u0111i\u1ec3m nh\u01b0 thu\u1ed9c t\u00ednh v\u00e0 kh\u00f4ng gian t\u00ean, XML c\u00f3 th\u1ec3 l\u00e0 l\u1ef1a ch\u1ecdn t\u1ed1t h\u01a1n.<\/span><\/p>\n<h3><strong>T\u1ea1i sao Python l\u00e0 ng\u00f4n ng\u1eef l\u00fd t\u01b0\u1edfng \u0111\u1ec3 l\u00e0m vi\u1ec7c v\u1edbi JSON?<\/strong><\/h3>\n<p><span style=\"font-weight: 400;\">Python l\u00e0 ng\u00f4n ng\u1eef l\u00fd t\u01b0\u1edfng \u0111\u1ec3 l\u00e0m vi\u1ec7c v\u1edbi JSON v\u00ec:<\/span><\/p>\n<ul>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>Th\u01b0 vi\u1ec7n t\u00edch h\u1ee3p:<\/b><span style=\"font-weight: 400;\"> Python c\u00f3 th\u01b0 vi\u1ec7n <\/span><span style=\"font-weight: 400;\">json<\/span><span style=\"font-weight: 400;\"> t\u00edch h\u1ee3p s\u1eb5n gi\u00fap \u0111\u1ecdc, ghi v\u00e0 x\u1eed l\u00fd JSON d\u1ec5 d\u00e0ng.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>C\u00fa ph\u00e1p \u0111\u01a1n gi\u1ea3n:<\/b><span style=\"font-weight: 400;\"> Python c\u00f3 c\u00fa ph\u00e1p \u0111\u01a1n gi\u1ea3n v\u00e0 d\u1ec5 h\u1ecdc, gi\u00fap l\u1eadp tr\u00ecnh vi\u00ean nhanh ch\u00f3ng l\u00e0m quen v\u00e0 x\u1eed l\u00fd d\u1eef li\u1ec7u JSON.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><b>H\u1ed7 tr\u1ee3 m\u1ea1nh m\u1ebd t\u1eeb c\u1ed9ng \u0111\u1ed3ng:<\/b><span style=\"font-weight: 400;\"> Python c\u00f3 m\u1ed9t c\u1ed9ng \u0111\u1ed3ng l\u1eadp tr\u00ecnh vi\u00ean l\u1edbn v\u00e0 nhi\u1ec1u t\u00e0i li\u1ec7u h\u01b0\u1edbng d\u1eabn, h\u1ed7 tr\u1ee3 vi\u1ec7c x\u1eed l\u00fd JSON m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3.<\/span><\/li>\n<\/ul>\n<h2><span class=\"ez-toc-section\" id=\"Tong_ket_JSON_Python_phan_2\"><\/span><b>T\u1ed5ng k\u1ebft <\/b><strong>JSON Python ph\u1ea7n 2<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><span style=\"font-weight: 400;\">\u0110\u00e2y l\u00e0 ph\u1ea7n cu\u1ed1i c\u1ee7a chu\u1ed7i b\u00e0i vi\u1ebft v\u1ec1 JSON v\u00e0 Python, nh\u1eefng \u1ee9ng d\u1ee5ng \u0111\u01b0\u1ee3c \u0111\u1ec1 c\u1eadp trong b\u00e0i vi\u00eat n\u00e0y kh\u00f4ng ch\u1ec9 gi\u00fap b\u1ea1n th\u1ea5y r\u00f5 vai tr\u00f2 c\u1ee7a JSON trong vi\u1ec7c ph\u00e1t tri\u1ec3n ph\u1ea7n m\u1ec1m m\u00e0 c\u00f2n cung c\u1ea5p c\u00e1c k\u1ef9 n\u0103ng c\u1ea7n thi\u1ebft \u0111\u1ec3 x\u1eed l\u00fd v\u00e0 qu\u1ea3n l\u00fd d\u1eef li\u1ec7u m\u1ed9t c\u00e1ch hi\u1ec7u qu\u1ea3. Hy v\u1ecdng qua chu\u1ed7i b\u00e0i vi\u1ebft v\u1ec1 JSON Python, b\u1ea1n \u0111\u00e3 thu th\u1eadp \u0111\u01b0\u1ee3c nhi\u1ec1u ki\u1ebfn th\u1ee9c v\u00e0 k\u1ef9 n\u0103ng h\u1eefu \u00edch \u0111\u1ec3 \u00e1p d\u1ee5ng v\u00e0o c\u00e1c d\u1ef1 \u00e1n c\u1ee7a m\u00ecnh.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Sau khi \u0111\u00e3\u00a0n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON trong Python bao g\u1ed3m c\u00e1ch \u0111\u1ecdc v\u00e0 ghi d\u1eef li\u1ec7u, chuy\u1ec3n \u0111\u1ed5i gi\u1eefa c\u00e1c \u0111\u1ecbnh d\u1ea1ng d\u1eef li\u1ec7u v\u00e0 l\u01b0u tr\u1eef JSON, b\u1ea1n s\u1ebd ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 nh\u1eefng \u1ee9ng d\u1ee5ng th\u1ef1c t\u1ebf c\u1ee7a JSON trong Python, gi\u00fap b\u1ea1n \u00e1p [&hellip;]<\/p>\n","protected":false},"author":222,"featured_media":77550,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_gspb_post_css":"","footnotes":""},"categories":[109],"tags":[],"class_list":["post-77307","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-chuyen-mon-it"],"blocksy_meta":[],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v26.8 (Yoast SEO v27.7) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON - ITviec Blog<\/title>\n<meta name=\"description\" content=\"Sau khi \u0111\u00e3\u00a0hi\u1ec3u c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON Python, c\u00f9ng ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 c\u00e1ch \u00e1p d\u1ee5ng JSON trong Python v\u00e0o th\u1ef1c t\u1ebf.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/\" \/>\n<meta property=\"og:locale\" content=\"vi_VN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON\" \/>\n<meta property=\"og:description\" content=\"Sau khi \u0111\u00e3\u00a0n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON trong Python bao g\u1ed3m c\u00e1ch \u0111\u1ecdc v\u00e0 ghi d\u1eef li\u1ec7u, chuy\u1ec3n \u0111\u1ed5i gi\u1eefa c\u00e1c \u0111\u1ecbnh d\u1ea1ng d\u1eef li\u1ec7u\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/\" \/>\n<meta property=\"og:site_name\" content=\"ITviec Blog\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/ITviec\" \/>\n<meta property=\"article:published_time\" content=\"2024-08-29T10:14:34+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/08\/python-json-thumbnail-vippro.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2850\" \/>\n\t<meta property=\"og:image:height\" content=\"1500\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Nguy\u1ec5n H\u1eefu V\u0103n\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@ITviec\" \/>\n<meta name=\"twitter:site\" content=\"@ITviec\" \/>\n<meta name=\"twitter:label1\" content=\"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi\" \/>\n\t<meta name=\"twitter:data1\" content=\"Nguy\u1ec5n H\u1eefu V\u0103n\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc\" \/>\n\t<meta name=\"twitter:data2\" content=\"11 ph\u00fat\" \/>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON - ITviec Blog","description":"Sau khi \u0111\u00e3\u00a0hi\u1ec3u c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON Python, c\u00f9ng ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 c\u00e1ch \u00e1p d\u1ee5ng JSON trong Python v\u00e0o th\u1ef1c t\u1ebf.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/","og_locale":"vi_VN","og_type":"article","og_title":"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON","og_description":"Sau khi \u0111\u00e3\u00a0n\u1eafm v\u1eefng c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON trong Python bao g\u1ed3m c\u00e1ch \u0111\u1ecdc v\u00e0 ghi d\u1eef li\u1ec7u, chuy\u1ec3n \u0111\u1ed5i gi\u1eefa c\u00e1c \u0111\u1ecbnh d\u1ea1ng d\u1eef li\u1ec7u","og_url":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/","og_site_name":"ITviec Blog","article_publisher":"https:\/\/www.facebook.com\/ITviec","article_published_time":"2024-08-29T10:14:34+00:00","og_image":[{"width":2850,"height":1500,"url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/08\/python-json-thumbnail-vippro.png","type":"image\/png"}],"author":"Nguy\u1ec5n H\u1eefu V\u0103n","twitter_card":"summary_large_image","twitter_creator":"@ITviec","twitter_site":"@ITviec","twitter_misc":{"\u0110\u01b0\u1ee3c vi\u1ebft b\u1edfi":"Nguy\u1ec5n H\u1eefu V\u0103n","\u01af\u1edbc t\u00ednh th\u1eddi gian \u0111\u1ecdc":"11 ph\u00fat"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#article","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/"},"author":{"name":"Nguy\u1ec5n H\u1eefu V\u0103n","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/a77cc13f89eaa58f59d8772448febe5f"},"headline":"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON","datePublished":"2024-08-29T10:14:34+00:00","mainEntityOfPage":{"@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/"},"wordCount":2823,"publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"image":{"@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/08\/python-json-thumbnail-vippro.png","articleSection":["Chuy\u00ean m\u00f4n IT"],"inLanguage":"vi"},{"@type":"WebPage","@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/","url":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/","name":"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON - ITviec Blog","isPartOf":{"@id":"https:\/\/itviec.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#primaryimage"},"image":{"@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#primaryimage"},"thumbnailUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/08\/python-json-thumbnail-vippro.png","datePublished":"2024-08-29T10:14:34+00:00","description":"Sau khi \u0111\u00e3\u00a0hi\u1ec3u c\u00e1c kh\u00e1i ni\u1ec7m n\u1ec1n t\u1ea3ng v\u00e0 c\u00e1ch l\u00e0m vi\u1ec7c v\u1edbi JSON Python, c\u00f9ng ti\u1ebfp t\u1ee5c kh\u00e1m ph\u00e1 c\u00e1ch \u00e1p d\u1ee5ng JSON trong Python v\u00e0o th\u1ef1c t\u1ebf.","breadcrumb":{"@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#breadcrumb"},"inLanguage":"vi","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/"]}]},{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#primaryimage","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/08\/python-json-thumbnail-vippro.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/08\/python-json-thumbnail-vippro.png","width":2850,"height":1500,"caption":"python json - itviec blog"},{"@type":"BreadcrumbList","@id":"https:\/\/itviec.com\/blog\/ung-dung-json-trong-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Chuy\u00ean m\u00f4n IT","item":"https:\/\/itviec.com\/blog\/chuyen-mon-it\/"},{"@type":"ListItem","position":2,"name":"JSON Python ph\u1ea7n 2: \u1ee8ng d\u1ee5ng d\u00f9ng Python \u0111\u1ec3 x\u1eed l\u00fd JSON"}]},{"@type":"WebSite","@id":"https:\/\/itviec.com\/blog\/#website","url":"https:\/\/itviec.com\/blog\/","name":"ITviec Blog","description":"IT Jobs &amp; People in Vietnam","publisher":{"@id":"https:\/\/itviec.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itviec.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"vi"},{"@type":"Organization","@id":"https:\/\/itviec.com\/blog\/#organization","name":"ITviec","url":"https:\/\/itviec.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2018\/12\/itviec-black-square-facebook.png","width":1800,"height":1800,"caption":"ITviec"},"image":{"@id":"https:\/\/itviec.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/ITviec","https:\/\/x.com\/ITviec","https:\/\/www.linkedin.com\/company\/itviec","https:\/\/www.youtube.com\/channel\/UCYthAQ3bcGr57M_ag5gHDvQ"]},{"@type":"Person","@id":"https:\/\/itviec.com\/blog\/#\/schema\/person\/a77cc13f89eaa58f59d8772448febe5f","name":"Nguy\u1ec5n H\u1eefu V\u0103n","image":{"@type":"ImageObject","inLanguage":"vi","@id":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/TR-Nguyen-Huu-Van-vippro-e1712136004193-100x100.jpg","url":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/TR-Nguyen-Huu-Van-vippro-e1712136004193-100x100.jpg","contentUrl":"https:\/\/itviec.com\/blog\/wp-content\/uploads\/2024\/03\/TR-Nguyen-Huu-Van-vippro-e1712136004193-100x100.jpg","caption":"Nguy\u1ec5n H\u1eefu V\u0103n"},"url":"https:\/\/itviec.com\/blog\/author\/nguyen-huu-van-2\/"}]}},"_links":{"self":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/77307","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/users\/222"}],"replies":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/comments?post=77307"}],"version-history":[{"count":0,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/posts\/77307\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media\/77550"}],"wp:attachment":[{"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/media?parent=77307"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/categories?post=77307"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itviec.com\/blog\/wp-json\/wp\/v2\/tags?post=77307"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}