JavaScript对json文件的读操作、遍历操作、清洗【json】

关于前后端交互中,前端常用的js处理Ajax接收到的json数据,进行后续的读取、遍历操作,以实现页面数据填充等。
常见场景(以微博热搜为例),

json读操作

先,从接口处爬下来

url ='https://weibo.com/ajax/side/hotSearch'
headers = {
        'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/96.0.4664.110 Safari/537.36'
    }
    # 响应
    r = requests.get(url,headers)

再,存储为文本一定要保存为json字符形式,保存r.json去json.cn上都解析不出来

    with open('D:/Temp/hot_search_ranking/data/data.json','w',encoding='utf-8') as fp:
        fp.write(r.text)

json字符形式(如下,键值对都带引号)

{"label_name":"","star_word":0,"word":"法国发现新冠新变异毒株IHU","category":"社会新闻","num":1282883,"subject_querys":"","flag":0,"onboard_time":1641383803,"raw_hot":1282883,"note":"法国发现新冠新变异毒株IHU","emoticon":"","ad_info":"","mid":"4722363411727060","realpos":1,"topic_flag":1,"channel_type":"","fun_word":0,"subject_label":"","rank":0}

下次,用的时候从文本中读取用的时候使用r.json,也就是用json对象

realTimeContent = r.json()['data']['realtime']

json 数据传回前端往往需要

    with open('D:/Temp/hot_search_ranking/data/data.json','r',encoding='utf-8') as fp:
        r = fp.read()#读json文件
        r = json.loads(r)['data']['realtime']#转json对象
        r = json.dumps(r)#转json文本,和json对象一模一样,不是json字符形式,它的键没有双引号,这是传输不能直接传json对象的才传文本的缘故
    return r

这样传输的是二进制文本

[{"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u897f\u5b89\u6709\u5c0f\u533a\u5f00\u59cb\u7edf\u8ba1\u5b55\u5987\u4fe1\u606f", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 1545054, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 1545054, "note": "\u897f\u5b89\u6709\u5c0f\u533a\u5f00\u59cb\u7edf\u8ba1\u5b55\u5987\u4fe1\u606f", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722340174762648", "onboard_time": 1641390467, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 1, "rank": 0}, {"label_name": "\u70ed", "star_word": 0, "word": "\u897f\u5b89\u8981\u6c42\u5bf9\u5b55\u4ea7\u5987\u7b49\u5f00\u901a\u7eff\u8272\u901a\u9053", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 1014694, "subject_querys": "", "flag": 2, "icon_desc": "\u70ed", "raw_hot": 1014694, "note": "\u897f\u5b89\u8981\u6c42\u5bf9\u5b55\u4ea7\u5987\u7b49\u5f00\u901a\u7eff\u8272\u901a\u9053", "emoticon": "", "is_hot": 1, "icon_desc_color": "#ff9406", "mid": "4722331668186725", "realpos": 2, "onboard_time": 1641376243, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 1}, {"label_name": "", "star_word": 0, "word": "\u628a\u63e1\u5386\u53f2\u4e3b\u52a8\u521b\u9020\u65b0\u7684\u4f1f\u4e1a", "category": "\u56fd\u5185\u8981\u95fb", "num": 978123, "subject_querys": "", "flag": 0, "onboard_time": 1641303290, "raw_hot": 621867, "note": "\u628a\u63e1\u5386\u53f2\u4e3b\u52a8\u521b\u9020\u65b0\u7684\u4f1f\u4e1a", "emoticon": "", "ad_info": "", "mid": "4722032266973549", "realpos": 3, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 2}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u51b0\u51b0\u5728\u51b0\u51b0\u7684\u51b0\u4e0a\u6ed1\u51b0", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 975276, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 1762069, "note": "\u51b0\u51b0\u5728\u51b0\u51b0\u7684\u51b0\u4e0a\u6ed1\u51b0", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722383736541462", "onboard_time": 1641391729, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 4, "rank": 3}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u4ee4\u4eba\u5fc3\u52a8\u7684offer\u674e\u4e0d\u8a00", "category": "\u7efc\u827a", "num": 975004, "realpos": 5, "flag": 1, "icon_desc": "\u65b0", "raw_hot": 1126361, "note": "\u4ee4\u4eba\u5fc3\u52a8\u7684offer\u674e\u4e0d\u8a00", "emoticon": "", "subject_label": "\u7efc\u827a", "icon_desc_color": "#ff3852", "mid": "4722364576699155", "flag_desc": "\u7efc\u827a", "subject_querys": "\u7efc\u827a|\u4ee4\u4eba\u5fc3\u52a8\u7684offer", "ad_info": "", "topic_flag": 0, "channel_type": "Entertainment", "fun_word": 1, "onboard_time": 1641392211, "rank": 4}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u5c0f\u7ea2\u4e66\u516c\u5e03\u7b2c\u4e8c\u6279\u8fdd\u89c4\u8425\u9500\u54c1\u724c\u5904\u7f5a\u540d\u5355", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 969185, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 969185, "note": "\u5c0f\u7ea2\u4e66\u516c\u5e03\u7b2c\u4e8c\u6279\u8fdd\u89c4\u8425\u9500\u54c1\u724c\u5904\u7f5a\u540d\u5355", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722333140650145", "onboard_time": 1641391607, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 6, "rank": 5}, {"icon_type": "kong", "id": 144586, "forbidden": {}, "icon": "", "is_ad": 1, "is_topic": 1, "monitors": {"app": {}, "pc": {}}, "end_time": 1641398400, "sort": 2, "is_star": 1, "name": "#\u5f20\u667a\u9716\u6768\u6021\u65b0\u5267\u597d\u6293\u9a6c#", "ad_type": "\u8d44\u6e90\u6295\u653e", "num": 927755, "dot_icon": 1, "word": "\u5f20\u667a\u9716\u6768\u6021\u65b0\u5267\u597d\u6293\u9a6c", "ad_channel": 2, "note": "\u5f20\u667a\u9716\u6768\u6021\u65b0\u5267\u597d\u6293\u9a6c", "topic_flag": 1, "monitor": {}, "start_time": 1641384000, "poi": 6, "rank": 5}, {"label_name": "\u70ed", "star_word": 0, "word": "\u9662\u65b9\u56de\u5e94\u5b55\u5987\u5728\u533b\u9662\u95e8\u53e3\u7b492\u5c0f\u65f6\u540e\u6d41\u4ea7", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 924636, "subject_querys": "", "flag": 2, "icon_desc": "\u70ed", "raw_hot": 924636, "note": "\u9662\u65b9\u56de\u5e94\u5b55\u5987\u5728\u533b\u9662\u95e8\u53e3\u7b492\u5c0f\u65f6\u540e\u6d41\u4ea7", "emoticon": "", "is_hot": 1, "icon_desc_color": "#ff9406", "mid": "4722304963055142", "realpos": 7, "onboard_time": 1641368746, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 6}, {"label_name": "", "star_word": 0, "word": "\u90bb\u5c45\u5403\u69b4\u83b2\u7537\u5b50\u4ee5\u4e3a\u7164\u6c14\u6cc4\u6f0f\u62a5\u706b\u8b66", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 768248, "subject_querys": "", "flag": 0, "onboard_time": 1641387406, "raw_hot": 768248, "note": "\u90bb\u5c45\u5403\u69b4\u83b2\u7537\u5b50\u4ee5\u4e3a\u7164\u6c14\u6cc4\u6f0f\u62a5\u706b\u8b66", "emoticon": "", "ad_info": "", "mid": "4722354066033913", "realpos": 8, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 7}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u8881\u5f18\u547c\u5401\u7537\u540c\u80de\u4ee5\u8463\u535a\u5b87\u4e3a\u6212", "category": "\u5f71\u89c6", "num": 720575, "realpos": 9, "flag": 1, "icon_desc": "\u65b0", "raw_hot": 720575, "note": "\u8881\u5f18\u547c\u5401\u7537\u540c\u80de\u4ee5\u8463\u535a\u5b87\u4e3a\u6212", "emoticon": "", "subject_label": "\u5267\u96c6", "icon_desc_color": "#ff3852", "mid": "4722356561383204", "flag_desc": "\u5267\u96c6", "subject_querys": "\u5267\u96c6|\u5e78\u798f\u4e8c\u91cd\u594f", "ad_info": "", "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "onboard_time": 1641388723, "rank": 8}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u5510\u827a\u6615\u8bf4\u7231\u60c5\u9700\u8981\u5f7c\u6b64\u643a\u624b\u5f25\u8865\u7f3a\u53e3", "category": "\u7efc\u827a", "num": 655500, "realpos": 10, "flag": 1, "icon_desc": "\u65b0", "raw_hot": 655500, "note": "\u5510\u827a\u6615\u8bf4\u7231\u60c5\u9700\u8981\u5f7c\u6b64\u643a\u624b\u5f25\u8865\u7f3a\u53e3", "emoticon": "", "subject_label": "\u7efc\u827a", "icon_desc_color": "#ff3852", "mid": "4722384537387643", "flag_desc": "\u7efc\u827a", "subject_querys": "\u7efc\u827a|\u534a\u719f\u604b\u4eba", "ad_info": "", "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "onboard_time": 1641390529, "rank": 9}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u5916\u5a46\u7ed910\u4e2a\u6708\u5a74\u513f\u522e\u75e7\u81f4\u5176\u9762\u90e8\u6e83\u70c2", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 645551, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 910115, "note": "\u5916\u5a46\u7ed910\u4e2a\u6708\u5a74\u513f\u522e\u75e7\u81f4\u5176\u9762\u90e8\u6e83\u70c2", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722376942551313", "onboard_time": 1641392211, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 11, "rank": 10}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u4e00\u5bb6\u4e09\u53e3\u5367\u5ba4\u70e4\u706b\u81f4\u4e00\u6c27\u5316\u78b3\u4e2d\u6bd2", "category": "\u793e\u4f1a\u8d1f\u9762", "num": 639352, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 821268, "note": "\u4e00\u5bb6\u4e09\u53e3\u5367\u5ba4\u70e4\u706b\u81f4\u4e00\u6c27\u5316\u78b3\u4e2d\u6bd2", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722404225975226", "onboard_time": 1641391550, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 12, "rank": 11}, {"label_name": "\u70ed", "star_word": 1, "word": "\u91d1\u7f8e\u79c0\u53bb\u4e16", "category": "\u827a\u4eba", "num": 639147, "subject_querys": "", "flag": 2, "icon_desc": "\u70ed", "raw_hot": 656722, "note": "\u91d1\u7f8e\u79c0\u53bb\u4e16", "emoticon": "[\u6cea]", "is_hot": 1, "icon_desc_color": "#ff9406", "mid": "4722296042555807", "realpos": 13, "onboard_time": 1641369043, "ad_info": "", "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "", "rank": 12}, {"label_name": "", "star_word": 0, "word": "\u6ca1\u6709\u5c0f\u670b\u53cb\u80fd\u62d2\u7edd\u8fd9\u4e2a\u793c\u7269", "category": "\u5e7d\u9ed8", "num": 630724, "subject_querys": "", "flag": 0, "onboard_time": 1641386684, "raw_hot": 630724, "note": "\u6ca1\u6709\u5c0f\u670b\u53cb\u80fd\u62d2\u7edd\u8fd9\u4e2a\u793c\u7269", "emoticon": "", "ad_info": "", "mid": "4722312522499377", "realpos": 14, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 13}, {"label_name": "", "star_word": 0, "word": "\u6cd5\u56fd\u53d1\u73b0\u65b0\u51a0\u65b0\u53d8\u5f02\u6bd2\u682aIHU", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 622929, "subject_querys": "", "flag": 0, "onboard_time": 1641383803, "raw_hot": 622929, "note": "\u6cd5\u56fd\u53d1\u73b0\u65b0\u51a0\u65b0\u53d8\u5f02\u6bd2\u682aIHU", "emoticon": "", "ad_info": "", "mid": "4722363411727060", "realpos": 15, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 14}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u5e02\u76d1\u603b\u5c40\u5bf9\u963f\u91cc\u817e\u8baf\u54d4\u54e9\u54d4\u54e9\u505a\u51fa\u884c\u653f\u5904\u7f5a", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 564688, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 564688, "note": "\u5e02\u76d1\u603b\u5c40\u5bf9\u963f\u91cc\u817e\u8baf\u54d4\u54e9\u54d4\u54e9\u505a\u51fa\u884c\u653f\u5904\u7f5a", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722236369930042", "onboard_time": 1641389806, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 16, "rank": 15}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u660e\u540e\u4e24\u5929\u5c06\u76f8\u7ee7\u4e0a\u6f14\u795e\u79d8\u5929\u8c61", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 464865, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 464865, "note": "\u660e\u540e\u4e24\u5929\u5c06\u76f8\u7ee7\u4e0a\u6f14\u795e\u79d8\u5929\u8c61", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722331438287915", "onboard_time": 1641390646, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 17, "rank": 16}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u7537\u5b69\u522e\u9c7c\u9cde\u5200\u5de5\u4e0d\u4e00\u822c", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 454099, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 454099, "note": "\u7537\u5b69\u522e\u9c7c\u9cde\u5200\u5de5\u4e0d\u4e00\u822c", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722294179499318", "onboard_time": 1641388966, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 18, "rank": 17}, {"label_name": "", "star_word": 0, "word": "\u90d1\u5dde\u65b0\u589e6\u4f8b\u9633\u6027", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 453908, "subject_querys": "", "flag": 0, "onboard_time": 1641386381, "raw_hot": 453908, "note": "\u90d1\u5dde\u65b0\u589e6\u4f8b\u9633\u6027", "emoticon": "", "ad_info": "", "mid": "4722375696845680", "realpos": 19, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 18}, {"label_name": "", "star_word": 0, "word": "\u6d59\u6c5f\u65b0\u589e3\u4f8b\u672c\u571f\u786e\u8bca", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 426021, "subject_querys": "", "flag": 0, "onboard_time": 1641386021, "raw_hot": 426021, "note": "\u6d59\u6c5f\u65b0\u589e3\u4f8b\u672c\u571f\u786e\u8bca", "emoticon": "", "ad_info": "", "mid": "4722393510054906", "realpos": 20, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 19}, {"label_name": "\u70ed", "star_word": 0, "word": "\u5b89\u5fbd\u660e\u786e\u518d\u5a5a\u5bb6\u5ead\u53ef\u518d\u751f\u80b2\u4e09\u4e2a\u5b50\u5973", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 421766, "subject_querys": "", "flag": 2, "icon_desc": "\u70ed", "raw_hot": 777817, "note": "\u5b89\u5fbd\u660e\u786e\u518d\u5a5a\u5bb6\u5ead\u53ef\u518d\u751f\u80b2\u4e09\u4e2a\u5b50\u5973", "emoticon": "", "is_hot": 1, "icon_desc_color": "#ff9406", "mid": "4722318469760524", "realpos": 21, "onboard_time": 1641379543, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 20}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u738b\u4e00\u535a\u5eff\u8de8\u5e74\u665a\u4f1a\u5f69\u6392\u82b1\u7d6e\u89c6\u9891", "category": "\u7efc\u827a", "num": 414930, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 513477, "note": "\u738b\u4e00\u535a\u5eff\u8de8\u5e74\u665a\u4f1a\u5f69\u6392\u82b1\u7d6e\u89c6\u9891", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722401793805457", "onboard_time": 1641392510, "ad_info": "", "topic_flag": 0, "channel_type": "Entertainment", "fun_word": 1, "realpos": 22, "rank": 21}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u897f\u5b89\u5168\u5e02\u6b63\u5728\u96c6\u4e2d\u9694\u79bb42000\u4f59\u4eba", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 397012, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 397012, "note": "\u897f\u5b89\u5168\u5e02\u6b63\u5728\u96c6\u4e2d\u9694\u79bb42000\u4f59\u4eba", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722331870299565", "onboard_time": 1641391188, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 23, "rank": 22}, {"label_name": "\u70ed", "star_word": 0, "word": "\u4eba\u6c11\u65e5\u62a5\u8bc4\u897f\u5b89\u9632\u75ab", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 386674, "subject_querys": "", "flag": 2, "icon_desc": "\u70ed", "raw_hot": 386674, "note": "\u4eba\u6c11\u65e5\u62a5\u8bc4\u897f\u5b89\u9632\u75ab", "emoticon": "", "is_hot": 1, "icon_desc_color": "#ff9406", "mid": "4722301847995845", "realpos": 24, "onboard_time": 1641371505, "ad_info": "", "topic_flag": 0, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 23}, {"label_name": "", "star_word": 0, "word": "\u5f53\u5357\u65b9\u72d7\u5230\u4e1c\u5317\u8fc7\u5e74", "category": "\u5e7d\u9ed8", "num": 375325, "subject_querys": "", "flag": 0, "onboard_time": 1641387524, "raw_hot": 375325, "note": "\u5f53\u5357\u65b9\u72d7\u5230\u4e1c\u5317\u8fc7\u5e74", "emoticon": "", "ad_info": "", "mid": "4722368583306958", "realpos": 25, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 24}, {"label_name": "", "star_word": 0, "word": "\u4e00\u4e2a\u5c0f\u602a\u7656\u5f15\u8d77\u4e86\u4e00\u573a\u7231\u60c5", "category": "\u60c5\u611f", "num": 357728, "subject_querys": "", "flag": 0, "onboard_time": 1641387945, "raw_hot": 357728, "note": "\u4e00\u4e2a\u5c0f\u602a\u7656\u5f15\u8d77\u4e86\u4e00\u573a\u7231\u60c5", "emoticon": "", "ad_info": "", "mid": "4722360689102193", "realpos": 26, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 25}, {"label_name": "", "star_word": 0, "word": "\u718a\u9edb\u6797\u597d\u50cf\u5c0f\u8bf4\u91cc\u7684\u6076\u6bd2\u5c11\u5976\u5976", "category": "\u5f71\u89c6", "num": 336044, "subject_querys": "\u5267\u96c6|\u5bb6\u65cf\u8363\u8000", "flag": 0, "onboard_time": 1641378132, "raw_hot": 336044, "note": "\u718a\u9edb\u6797\u597d\u50cf\u5c0f\u8bf4\u91cc\u7684\u6076\u6bd2\u5c11\u5976\u5976", "emoticon": "", "ad_info": "", "mid": "4722346496360983", "flag_desc": "\u5267\u96c6", "realpos": 27, "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 26}, {"label_name": "", "star_word": 0, "word": "\u738b\u724c\u90e8\u961f\u987e\u4e00\u91ce\u51b3\u5b9a\u7167\u987e\u963f\u79c0", "category": "\u5f71\u89c6", "num": 331729, "subject_querys": "\u5267\u96c6|\u738b\u724c\u90e8\u961f", "flag": 0, "onboard_time": 1641379069, "raw_hot": 331729, "note": "\u738b\u724c\u90e8\u961f\u987e\u4e00\u91ce\u51b3\u5b9a\u7167\u987e\u963f\u79c0", "emoticon": "", "ad_info": "", "mid": "4722383221424691", "flag_desc": "\u5267\u96c6", "realpos": 28, "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 27}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u5343\u4e07\u4e0d\u8981\u5728\u997f\u7684\u65f6\u5019\u770b\u5c0f\u8bf4", "category": "\u7f8e\u98df", "num": 290343, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 290343, "note": "\u5343\u4e07\u4e0d\u8981\u5728\u997f\u7684\u65f6\u5019\u770b\u5c0f\u8bf4", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722377943943389", "onboard_time": 1641390285, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 29, "rank": 28}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u6d59\u6c5f\u6c38\u5eb7\u901a\u62a5\u4e00\u4f8b\u9633\u6027", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 289463, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 289463, "note": "\u6d59\u6c5f\u6c38\u5eb7\u901a\u62a5\u4e00\u4f8b\u9633\u6027", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722393510054906", "onboard_time": 1641392873, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 30, "rank": 29}, {"label_name": "", "star_word": 0, "word": "\u6768\u5e42\u767e\u82b1\u8fce\u6625\u665a\u4f1a\u4e0a\u73ed\u56fe", "category": "\u7efc\u827a", "num": 283388, "subject_querys": "\u665a\u4f1a|\u6587\u8054\u6625\u665a", "flag": 0, "onboard_time": 1641382122, "raw_hot": 332051, "note": "\u6768\u5e42\u767e\u82b1\u8fce\u6625\u665a\u4f1a\u4e0a\u73ed\u56fe", "emoticon": "", "ad_info": "", "mid": "4722378745054021", "realpos": 31, "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "", "rank": 30}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u674e\u65af\u4e39\u59ae\u4e00\u4e2a\u4eba\u5c31\u662f\u4e00\u53f0\u665a\u4f1a", "category": "\u7efc\u827a", "num": 282342, "realpos": 32, "flag": 1, "icon_desc": "\u65b0", "raw_hot": 324363, "note": "\u674e\u65af\u4e39\u59ae\u4e00\u4e2a\u4eba\u5c31\u662f\u4e00\u53f0\u665a\u4f1a", "emoticon": "", "subject_label": "\u665a\u4f1a", "icon_desc_color": "#ff3852", "mid": "4722308364894860", "flag_desc": "\u665a\u4f1a", "subject_querys": "\u665a\u4f1a|\u8292\u679c\u5e74\u8d27\u8282", "ad_info": "", "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "onboard_time": 1641389266, "rank": 31}, {"label_name": "", "star_word": 0, "word": "\u8096\u6218\u987e\u4e00\u91ce", "category": "\u5f71\u89c6", "num": 281434, "subject_querys": "\u5267\u96c6|\u738b\u724c\u90e8\u961f", "flag": 0, "onboard_time": 1641383323, "raw_hot": 435332, "note": "\u8096\u6218\u987e\u4e00\u91ce", "emoticon": "[\u6cea]", "ad_info": "", "mid": "4722383221424691", "flag_desc": "\u5267\u96c6", "realpos": 33, "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 32}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u820d\u4e0d\u5f97\u5206\u4eab\u7ed9\u59d0\u59b9\u7684\u5973\u88c5\u5e97", "category": "\u65f6\u5c1a", "num": 276061, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 276061, "note": "\u820d\u4e0d\u5f97\u5206\u4eab\u7ed9\u59d0\u59b9\u7684\u5973\u88c5\u5e97", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722376694563028", "onboard_time": 1641392748, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 34, "rank": 33}, {"label_name": "", "star_word": 0, "word": "\u96ea\u4e2d\u608d\u5200\u884c", "category": "\u5f71\u89c6", "num": 274052, "subject_querys": "\u5267\u96c6|\u96ea\u4e2d\u608d\u5200\u884c", "flag": 0, "onboard_time": 1641386080, "raw_hot": 274052, "note": "\u96ea\u4e2d\u608d\u5200\u884c", "emoticon": "", "ad_info": "", "mid": "4722213402447003", "flag_desc": "\u5267\u96c6", "realpos": 35, "topic_flag": 0, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 34}, {"label_name": "", "star_word": 0, "word": "\u80e1\u6b4c\u8bf4\u5b8c\u7f8e\u4f34\u4fa3\u6211\u719f\u554a", "category": "\u5f71\u89c6", "num": 269357, "subject_querys": "\u5267\u96c6|\u5b8c\u7f8e\u4f34\u4fa3", "flag": 0, "onboard_time": 1641384043, "raw_hot": 269357, "note": "\u80e1\u6b4c\u8bf4\u5b8c\u7f8e\u4f34\u4fa3\u6211\u719f\u554a", "emoticon": "", "ad_info": "", "mid": "4722328954997845", "flag_desc": "\u5267\u96c6", "realpos": 36, "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 35}, {"label_name": "\u65b0", "is_new": 1, "star_word": 1, "word": "\u5f20\u96e8\u7eee\u65f6\u5c1a\u5148\u751f\u5e74\u5ea6\u7f8e\u4e3d\u5973\u4eba", "category": "\u65f6\u5c1a,\u827a\u4eba", "num": 255086, "subject_querys": "\u76db\u5178|\u65f6\u5c1a\u5148\u751f", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 255086, "note": "\u5f20\u96e8\u7eee\u65f6\u5c1a\u5148\u751f\u5e74\u5ea6\u7f8e\u4e3d\u5973\u4eba", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722374177457960", "onboard_time": 1641392510, "ad_info": "", "topic_flag": 1, "channel_type": "Entertainment", "fun_word": 1, "realpos": 37, "rank": 36}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u793e\u6050\u7537\u751f\u4e0d\u6562\u5f53\u4f17\u6f14\u8bb2\u5168\u73ed\u5411\u540e\u8f6c\u914d\u5408", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 255070, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 255070, "note": "\u793e\u6050\u7537\u751f\u4e0d\u6562\u5f53\u4f17\u6f14\u8bb2\u5168\u73ed\u5411\u540e\u8f6c\u914d\u5408", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722330276726230", "onboard_time": 1641392634, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 38, "rank": 37}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u8fd1\u8ddd\u79bb\u770b\u9cb8\u9c7c\u53ef\u4ee5\u6709\u591a\u9707\u64bc", "category": "\u81ea\u7136", "num": 248269, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 248269, "note": "\u8fd1\u8ddd\u79bb\u770b\u9cb8\u9c7c\u53ef\u4ee5\u6709\u591a\u9707\u64bc", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722373474127391", "onboard_time": 1641390348, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 39, "rank": 38}, {"label_name": "", "star_word": 0, "word": "\u90d1\u5dde\u672c\u8f6e\u75ab\u60c5\u4e3b\u8981\u7531\u5fb7\u5c14\u5854\u6bd2\u682a\u5f15\u8d77", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 245249, "subject_querys": "", "flag": 0, "onboard_time": 1641387045, "raw_hot": 245249, "note": "\u90d1\u5dde\u672c\u8f6e\u75ab\u60c5\u4e3b\u8981\u7531\u5fb7\u5c14\u5854\u6bd2\u682a\u5f15\u8d77", "emoticon": "", "ad_info": "", "mid": "4722353525230760", "realpos": 40, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 39}, {"label_name": "", "star_word": 0, "word": "\u738b\u724c\u90e8\u961f", "category": "\u5f71\u89c6", "num": 228755, "subject_querys": "\u5267\u96c6|\u738b\u724c\u90e8\u961f", "flag": 0, "onboard_time": 1641364185, "raw_hot": 228755, "note": "\u738b\u724c\u90e8\u961f", "emoticon": "[\u6cea]", "ad_info": "", "mid": "4722349678789350", "flag_desc": "\u5267\u96c6", "realpos": 41, "topic_flag": 0, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 40}, {"label_name": "", "star_word": 0, "word": "\u897f\u5b89\u75ab\u60c5\u793e\u4f1a\u9762\u57fa\u672c\u5b9e\u73b0\u6e05\u96f6", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 220701, "subject_querys": "", "flag": 0, "onboard_time": 1641375161, "raw_hot": 220701, "note": "\u897f\u5b89\u75ab\u60c5\u793e\u4f1a\u9762\u57fa\u672c\u5b9e\u73b0\u6e05\u96f6", "emoticon": "", "ad_info": "", "mid": "4722326367633487", "realpos": 42, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 41}, {"label_name": "", "star_word": 0, "word": "\u9ad8\u5706\u5706\u6f14\u7684\u5f8b\u5e08\u9648\u73ca", "category": "\u5f71\u89c6", "num": 198706, "subject_querys": "\u5267\u96c6|\u5b8c\u7f8e\u4f34\u4fa3", "flag": 0, "onboard_time": 1641381943, "raw_hot": 198706, "note": "\u9ad8\u5706\u5706\u6f14\u7684\u5f8b\u5e08\u9648\u73ca", "emoticon": "", "ad_info": "", "mid": "4722371690759512", "flag_desc": "\u5267\u96c6", "realpos": 43, "topic_flag": 0, "channel_type": "Entertainment", "fun_word": 1, "subject_label": "\u5267\u96c6", "rank": 42}, {"label_name": "", "star_word": 0, "word": "iQOO9", "category": "\u79d1\u6280", "num": 196668, "subject_querys": "", "flag": 0, "onboard_time": 1641383565, "raw_hot": 196668, "note": "iQOO9", "emoticon": "", "ad_info": "", "mid": "4722383187871051", "realpos": 44, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 43}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u6d59\u6c5f\u91d1\u534e\u901a\u62a51\u4f8b\u9633\u6027", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 190370, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 190370, "note": "\u6d59\u6c5f\u91d1\u534e\u901a\u62a51\u4f8b\u9633\u6027", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722394029623542", "onboard_time": 1641393235, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 45, "rank": 44}, {"label_name": "", "star_word": 0, "word": "\u7f57\u6c38\u6d69\u9650\u5236\u9ad8\u6d88\u8d39\u4fe1\u606f\u6e05\u96f6", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 183084, "subject_querys": "", "flag": 0, "onboard_time": 1641374383, "raw_hot": 183084, "note": "\u7f57\u6c38\u6d69\u9650\u5236\u9ad8\u6d88\u8d39\u4fe1\u606f\u6e05\u96f6", "emoticon": "", "ad_info": "", "mid": "4722338019149010", "realpos": 46, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 45}, {"label_name": "", "star_word": 0, "word": "\u897f\u5b89\u4e00\u623f\u4e1c\u7ed9\u79df\u5ba2\u514d\u4e00\u4e2a\u6708\u623f\u79df", "category": "\u793e\u4f1a\u6b63\u80fd\u91cf", "num": 175798, "subject_querys": "", "flag": 0, "onboard_time": 1641381223, "raw_hot": 175798, "note": "\u897f\u5b89\u4e00\u623f\u4e1c\u7ed9\u79df\u5ba2\u514d\u4e00\u4e2a\u6708\u623f\u79df", "emoticon": "", "ad_info": "", "mid": "4722319887173394", "realpos": 47, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 46}, {"label_name": "", "star_word": 0, "word": "\u90d1\u5dde\u7d2f\u8ba17\u4f8b\u786e\u8bca10\u4f8b\u65e0\u75c7\u72b6", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 164671, "subject_querys": "", "flag": 0, "onboard_time": 1641386205, "raw_hot": 164671, "note": "\u90d1\u5dde\u7d2f\u8ba17\u4f8b\u786e\u8bca10\u4f8b\u65e0\u75c7\u72b6", "emoticon": "", "ad_info": "", "mid": "4722370872871100", "realpos": 48, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 47}, {"label_name": "", "star_word": 0, "word": "\u6d59\u6c5f\u7b2c100\u573a\u75ab\u60c5\u53d1\u5e03\u4f1a", "category": "\u793e\u4f1a\u65b0\u95fb", "num": 143367, "subject_querys": "", "flag": 0, "onboard_time": 1641386864, "raw_hot": 143367, "note": "\u6d59\u6c5f\u7b2c100\u573a\u75ab\u60c5\u53d1\u5e03\u4f1a", "emoticon": "", "ad_info": "", "mid": "4722369992592104", "realpos": 49, "topic_flag": 1, "channel_type": "", "fun_word": 0, "subject_label": "", "rank": 48}, {"label_name": "\u65b0", "is_new": 1, "star_word": 0, "word": "\u5f53\u8def\u4e0a\u591a\u4e86\u4e00\u4e2a\u8df3\u623f\u5b50\u65f6", "category": "\u5e7d\u9ed8", "num": 134672, "subject_querys": "", "flag": 1, "icon_desc": "\u65b0", "raw_hot": 134672, "note": "\u5f53\u8def\u4e0a\u591a\u4e86\u4e00\u4e2a\u8df3\u623f\u5b50\u65f6", "emoticon": "", "subject_label": "", "icon_desc_color": "#ff3852", "mid": "4722388426558263", "onboard_time": 1641393534, "ad_info": "", "topic_flag": 1, "channel_type": "", "fun_word": 0, "realpos": 50, "rank": 49}]127.0.0.1 - - [05/Jan/2022 22:51:14] "GET /timelinechart/ HTTP/1.1" 200 -

json遍历

下面的遍历优点在于不需要知道key具体是什么
//原生js遍历JSON
 $.ajax({
        type: "GET",
        dataType: "json",
        url: "/data",
        //data: { id: id, name: name },
        success: function(json) {   
               
          for(var i=0;i<json.length;i++){
            for(var key in json[i]){
              alert(key+':'+json[i][key]);
            }
          }
 
        },
        error: function(json) {
          
        }
      });
//jQuery遍历JSON

var json_1 = {"name":"jim","age":"28"};

$.each(json_1,function(key,value){   //其中key是json的key,value指相对应的值;

        console.log(key +" : " + value);

})

清洗

新手,hhh,我就把没必要的键值对扔了。
 //清洗
          for(var i=0;i<json.length;i++){
            delete json[i]['is_new'];
            delete json[i]['star_word'];
            delete json[i]['word'];
            delete json[i]['realpos'];
            delete json[i]['flag'];
            delete json[i]['raw_hot'];
            delete json[i]['emoticon'];
            delete json[i]['subject_label'];
            delete json[i]['icon_desc_color'];
            delete json[i]['flag_desc'];
            delete json[i]['subject_querys'];
            delete json[i]['ad_info'];
            delete json[i]['topic_flag'];
            delete json[i]['fun_word'];
            delete json[i]['icon_desc'];
            
          }
  • 1
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
使用SPSS、机器学习、自然语言处理等方法,对收集到的文本数据进行分词、数据清洗、词频统计和聚类分析。最后根据所得到的数据进行以及分析,发现目前在线教学 中学生体验的现状、趋势以及一些待解决的问题。 爬虫(Web Crawler)是一种自动化程序,用于从互联网上收集信息。其主要功能是访问网页、提取数据并存储,以便后续分析或展示。爬虫通常由搜索引擎、数据挖掘工具、监测系统等应用于网络数据抓取的场景。 爬虫的工作流程包括以下几个关键步骤: URL收集: 爬虫从一个或多个初始URL开始,递归或迭代地发现新的URL,构建一个URL队列。这些URL可以通过链接分析、站点地图、搜索引擎等方式获取。 请求网页: 爬虫使用HTTP或其他协议向目标URL发起请求,获取网页的HTML内容。这通常通过HTTP请求库实现,如Python中的Requests库。 解析内容: 爬虫对获取的HTML进行解析,提取有用的信息。常用的解析工具有正则表达式、XPath、Beautiful Soup等。这些工具帮助爬虫定位和提取目标数据,如文本、图片、链接等。 数据存储: 爬虫将提取的数据存储到数据库、文件或其他存储介质中,以备后续分析或展示。常用的存储形式包括关系型数据库、NoSQL数据库、JSON文件等。 遵守规则: 为避免对网站造成过大负担或触发反爬虫机制,爬虫需要遵守网站的robots.txt协议,限制访问频率和深度,并模拟人类访问行为,如设置User-Agent。 反爬虫应对: 由于爬虫的存在,一些网站采取了反爬虫措施,如验证码、IP封锁等。爬虫工程师需要设计相应的策略来应对这些挑战。 爬虫在各个领域都有广泛的应用,包括搜索引擎索引、数据挖掘、价格监测、新闻聚合等。然而,使用爬虫需要遵守法律和伦理规范,尊重网站的使用政策,并确保对被访问网站的服务器负责。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

来杯Sherry

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值