HTML 实体的 JSON 序列化

问题描述 投票:0回答:1

在对包含 HTML 数据的 JSON 字符串进行反序列化时,我注意到以下情况:

  • <
    >
    转换为
    \u003c
    \u003e

    (直接unicode表示)
  • &
    转换为
    \u0026amp;

    (HTML 实体的 Unicode 表示
    &amp;

区别对待这两者的原因可能是什么?序列化器产生的结果不准确还是我遗漏了什么?




包含完整的 JSON 字符串,以防万一有人想要引用(复制)

{
    "html" : "\u003c!DOCTYPE html\u003e\n\u003chtml prefix=\"dc: http://purl.org/dc/terms/ mw: http://mediawiki.org/rdf/\" about=\"https://en.wikipedia.org/wiki/Special:Redirect/revision/1167349238\"\u003e\u003chead prefix=\"mwr: https://en.wikipedia.org/wiki/Special:Redirect/\"\u003e\u003cmeta property=\"mw:TimeUuid\" content=\"627f4410-2c44-11ee-b295-07334e9dc8f2\"/\u003e\u003cmeta charset=\"utf-8\"/\u003e\u003cmeta property=\"mw:pageId\" content=\"35562150\"/\u003e\u003cmeta property=\"mw:pageNamespace\" content=\"0\"/\u003e\u003clink rel=\"dc:replaces\" resource=\"mwr:revision/488309642\"/\u003e\u003cmeta property=\"mw:revisionSHA1\" content=\"e917c5f8579fbb8c54fea8cee881482527137550\"/\u003e\u003cmeta property=\"dc:modified\" content=\"2023-07-27T06:11:10.000Z\"/\u003e\u003cmeta property=\"mw:htmlVersion\" content=\"2.8.0\"/\u003e\u003cmeta property=\"mw:html:version\" content=\"2.8.0\"/\u003e\u003clink rel=\"dc:isVersionOf\" href=\"//en.wikipedia.org/wiki/Stunn\"/\u003e\u003cbase href=\"//en.wikipedia.org/wiki/\"/\u003e\u003ctitle\u003eStunn\u003c/title\u003e\u003cmeta property=\"mw:generalModules\" content=\"ext.cite.ux-enhancements\"/\u003e\u003cmeta property=\"mw:moduleStyles\" content=\"ext.cite.style|ext.cite.styles\"/\u003e\u003clink rel=\"stylesheet\" href=\"/w/load.php?lang=en\u0026amp;modules=ext.cite.style%7Cext.cite.styles%7Cmediawiki.skinning.content.parsoid%7Cmediawiki.skinning.interface%7Csite.styles\u0026amp;only=styles\u0026amp;skin=vector\"/\u003e\u003cmeta http-equiv=\"content-language\" content=\"en\"/\u003e\u003cmeta http-equiv=\"vary\" content=\"Accept\"/\u003e\u003c/head\u003e\u003cbody id=\"mwAA\" lang=\"en\" class=\"mw-content-ltr sitedir-ltr ltr mw-body-content parsoid-body mediawiki mw-parser-output\" dir=\"ltr\"\u003e\u003csection data-mw-section-id=\"0\" id=\"mwAQ\"\u003e\u003cp id=\"mwAg\"\u003e\u003csup about=\"#mwt2\" class=\"mw-ref reference\" id=\"cite_ref-1\" rel=\"dc:references\" typeof=\"mw:Extension/ref mw:Error\" data-mw='{\"name\":\"ref\",\"attrs\":{},\"body\":{\"html\":\"\"},\"errors\":[{\"key\":\"cite_error_ref_no_input\"}]}'\u003e\u003ca href=\"./Stunn#cite_note-1\" style=\"counter-reset: mw-Ref 1;\" id=\"mwAw\"\u003e\u003cspan class=\"mw-reflink-text\" id=\"mwBA\"\u003e[1]\u003c/span\u003e\u003c/a\u003e\u003c/sup\u003e\nLourell Andymark George alias Stunn formerlly known as Stunna was born on ( February 11,1998) is a talented Liberian singer, songwriter, and actor is now on the rise of being one of Africa’s pride musical artists hailing from the vibrant West African nation of Liberia a, he was inspired to pursue a career in music after forming group called  Swag District with now musicians call J. slught and rapper Nuchie Meek . He is the recipient of several accolades, RNB Artist of the Year 2018 (Tunes Liberia), RnB Artist of the Year (Tunes Liberia), MLMA Afropop Artist of the Year 2021, and MLMA Video of the year 2020.\u003ca rel=\"mw:ExtLink nofollow\" href=\"https://www.musicinafrica.net/magazine/mtn-liberia-music-awards-2020-all-winners\" class=\"external free\" id=\"mwBQ\"\u003ehttps://www.musicinafrica.net/magazine/mtn-liberia-music-awards-2020-all-winners\u003c/a\u003e, \u003ca rel=\"mw:ExtLink nofollow\" href=\"https://www.musicinafrica.net/magazine/tunesliberia-music-awards-2020-all-winners\" class=\"external free\" id=\"mwBg\"\u003ehttps://www.musicinafrica.net/magazine/tunesliberia-music-awards-2020-all-winners\u003c/a\u003e, \u003ca rel=\"mw:ExtLink nofollow\" href=\"https://www.musicinafrica.net/magazine/mtn-liberia-music-awards-2021-all-nominees\" class=\"external free\" id=\"mwBw\"\u003ehttps://www.musicinafrica.net/magazine/mtn-liberia-music-awards-2021-all-nominees\u003c/a\u003e\u003c/p\u003e\n\n\u003cp id=\"mwCA\"\u003eEarly life and career\u003c/p\u003e\n\n\u003cp id=\"mwCQ\"\u003eLourell Andymark George  was born on Feburary 11,1998 in Monrovia, Monsterrado County.He studied Economics and business management at AME University and graduated in 2021.[2] Prior to pursuing a career in music, he worked as an Freelance Writer.[2] Stunn met singer and record producer J. Slught and Nuchie Meek  while in school and formed the group Swag District. He released his first single, “Zoko Love” featuring his former label mate, A Raw on August 31, 2016.\u003c/p\u003e\n\n\u003cp id=\"mwCg\"\u003eStunn, born with a passion for music, has emerged as a prominent figure in the Liberian music scene following the release of his debut hit single  in 2018, (Baby O) which quickly gained attraction and earned him recognition among both fans and industry professionals captivating audiences with his unique style and performances.\u003c/p\u003e\n\n\u003cp id=\"mwCw\"\u003eThe Star 2019 gained much recognition from major international media houses like BBC, FrontPage-Africa, Music in Africa, and many others for his support and teaching of the cultural heritage of Liberia through music. Many of these educational events have enabled others to learn about the diversity of the culture of Liberia through music.\u003c/p\u003e\n \n\u003cp id=\"mwDA\"\u003eOver the year, he has been more engaged in teaching and coaching upcoming Entertainers and Artists on Liberia’s culture and traditional music. He has been the brain behind so many of Liberia’s hit songs and has been a big inspiration to up-and-coming artists as well. His style of teaching, coaching, and performance has enabled people to learn about the cultural heritage of Libera through music in which he blends traditional sounds in a unique style, lyrics, traditional drumbeat, vocally, and rhymes.\u003ca rel=\"mw:ExtLink nofollow\" href=\"https://www.bbc.co.uk/programmes/m0019kzl\" class=\"external free\" id=\"mwDQ\"\u003ehttps://www.bbc.co.uk/programmes/m0019kzl\u003c/a\u003e\n\u003ca rel=\"mw:ExtLink nofollow\" href=\"https://frontpageafricaonline.com/entertainment/trending-liberian-musicians-stunna-mc-caro-appear-on-bbc-1xtra-show-following-his-new-single-title-green-light/\" class=\"external free\" id=\"mwDg\"\u003ehttps://frontpageafricaonline.com/entertainment/trending-liberian-musicians-stunna-mc-caro-appear-on-bbc-1xtra-show-following-his-new-single-title-green-light/\u003c/a\u003e\u003c/p\u003e\n\n\u003cp id=\"mwDw\"\u003eApart from his collaborations with some of Liberia’s most popular musicians like Kobazzie, PCK, Teddyride, Bucky Raw, Jaredo, and more, Stunna was able to get on two songs with international artists Iyanya and Ice Prince.\nIn early 2018, Stunna recorded and shot the video for his song, “Balance” which featured hit maker, Iyanya, and went on to get nominations at prestigious Liberian awards. At the end of 2018, Stunna and Bucky Raw flew to Nigeria to work on yet another video and song with an international artist – Ice Prince – dubbed, “Thank You”.\nStunna has gone on to win awards from the Tunes Liberia Music Awards, as well as receiving several nominations from the LMA, LEA and other local award programs.\u003c/p\u003e\n\n\u003cp id=\"mwEA\"\u003eOn 22nd July 2022, Stunn released \" Greenlight\" Under his new Manager Pumpaye CEO of AEG Inspire after taking sevral months from the musical scene to work on his personal and musical growth . \u003ca rel=\"mw:ExtLink nofollow\" href=\"https://www.theghanareport.com/stunna-to-popularise-liberian-music-in-ghana/\" class=\"external free\" id=\"mwEQ\"\u003ehttps://www.theghanareport.com/stunna-to-popularise-liberian-music-in-ghana/\u003c/a\u003e\u003c/p\u003e\n\n\u003cp id=\"mwEg\"\u003eHe is also known as the face of Afropop (“Afropop, a music genre that has been described as \"as colorful as the continent of Africa itself,\" blends traditional sounds from African countries with Western influences to create something completely distinct.”)  in Liberia, he has transitioned Afropop in a unique style, rhythms, and lyrics, and blend that with the traditional music of Liberia in which he has created Events, coaching, and mentoring upcoming Artists and entertainers.\u003c/p\u003e\n\u003cdiv class=\"mw-references-wrap\" typeof=\"mw:Extension/references\" about=\"#mwt3\" data-mw='{\"name\":\"references\",\"attrs\":{},\"autoGenerated\":true}' id=\"mwEw\"\u003e\u003col class=\"mw-references references\" id=\"mwFA\"\u003e\u003cli about=\"#cite_note-1\" id=\"cite_note-1\"\u003e\u003ca href=\"./Stunn#cite_ref-1\" rel=\"mw:referencedBy\" id=\"mwFQ\"\u003e\u003cspan class=\"mw-linkback-text\" id=\"mwFg\"\u003e↑ \u003c/span\u003e\u003c/a\u003e \u003cspan id=\"mw-reference-text-cite_note-1\" class=\"mw-reference-text\"\u003e\u003c/span\u003e\u003c/li\u003e\u003c/ol\u003e\u003c/div\u003e\u003c/section\u003e\u003c/body\u003e\u003c/html\u003e"
}
json escaping html-entities html-encode json-serialization
1个回答
0
投票

这很愚蠢。

  • &
    是HTML内容的一部分,所以它被转换为HTML实体 首先。
  • 另一方面,
  • <
    是 HTML 标签的一部分。如果有一个 内容中的
    <
    ,它会转换为
    \u0026lt;
© www.soinside.com 2019 - 2024. All rights reserved.