如何修复API返回的数据中的JSON问题?

时间:2017-10-07 18:53:01

标签: python json

我正在使用WordPress.org插件API(不是WordPress插件API,而是实际的wordpress.org插件API)。我已经将JSON写入一堆文件中,其中包含各种插件的详细信息。其中大多数都很有效,但是在这个问题上偶尔会出现问题:

{
    "name": "2046's Loop widget",
    "slug": "2046s-widget-loops",
    "version": "1.0",
    "author": "<a href=\"http://2046.cz\">2046</a>",
    "author_profile": "https://profiles.wordpress.org/o-o",
    "requires": "3.1",
    "tested": "3.4.2",
    "requires_php": false,
    "compatibility": [],
    "rating": 100,
    "ratings": {
        "5": 1,
        "4": 0,
        "3": 0,
        "2": 0,
        "1": 0
    },
    "num_ratings": 1,
    "support_threads": 0,
    "support_threads_resolved": 0,
    "downloaded": 9091,
    "last_updated": "2012-11-26 10:16pm GMT",
    "added": "2012-02-06",
    "homepage": "http://wordpress.org/extend/plugins/2046s-widget-loops/",
    "sections": {
        "description": "<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe class='youtube-player' type='text/html' width='640' height='390' src='https://www.youtube.com/embed/dU8Qll6Wqes?version=3&rel=1&fs=1&autohide=2&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent' allowfullscreen='true' style='border:0;'></iframe></span></p>\n<p>When you build the content with “2046’s loop widget”, the only thing you have to decide is what content you want to see and where. All the programming you always wanted to avoid is gone.<br />\nThe widget covers the most routinely used content logic. The aim of this widget is to speed up the process of content structuring and simplicity of usage while keeping the standards.</p>\n<h4>Note</h4>\n<p>I highly encourage you to use the “Easy” instead of 2046’s loop widget. <a href=\"https://wordpress.org/extend/plugins/easy/screenshots/\" rel=\"nofollow\">Easy</a> is a new version of 2046 loop widgets.  It’s is much more flexible and in active development.</p>\n<p>Why I made different Plugin of the same type?<br />\nWell some people use the 2046’s loop widget already and are “used to it”. Most importantly the Easy is totally different animal although with similar functions.</p>\n<p>“A picture better be worth a thousand words.” Don’t forget to check <a href=\"https://wordpress.org/extend/plugins/2046s-widget-loops/screenshots/\" rel=\"nofollow\">screenshots</a>.</p>\n<h4>Localization</h4>\n<ul>\n<li>English</li>\n<li>Czech</li>\n</ul>\n<h4>Compatibility</h4>\n<p>Tested with <a href=\"https://wordpress.org/extend/plugins/custom-content-type-manager/\" rel=\"nofollow\">CCTM</a>, <a href=\"More Types\" rel=\"nofollow\">More types</a>, <a href=\"https://wordpress.org/extend/plugins/more-taxonomies/\" rel=\"nofollow\">More taxonomies</a>, <a href=\"http://wpml.org/\" rel=\"nofollow\">WPML</a>.<br />\n<a href=\"https://wordpress.org/extend/plugins/wp-pagenavi/\" rel=\"nofollow\">WP-PageNavi</a> ready.<br />\n<a href=\"http://twitter.github.com/\" rel=\"nofollow\">Bootstrap</a> ready.</p>\n",
        "installation": "<p>If you are installing 2046’s loop widgets for the first time, follow these steps:</p>\n<ol>\n<li>Upload the <code>2046s-widget-loops</code> folder to <code>/wp-content/plugins/</code> abs activate it in the admin plugin area.</li>\n<li>Else, download and activate the plugin through the ‘Plugins’ in the WordPress adimin area.</li>\n</ol>\n<p>Widget has no extra settings. All the settings are done in the widget area as like for any other normal widget.</p>\n",
        "faq": "\n<h4>How can I use it`?</h4>\n<p>\n<p>First you have to have some dynamic sidebars defined.<br />\nSome themes have them registered already, but I doubt they have them in the main content area where this loop widget meets it’s intention.<br />\n(Most of the templates have them only in so called sidebars, or header. Widgets are commonly are used for category listing, tag cloud, Facebook features etc.)<br />\n<em>The dynamic sidebar is a “slot” where you can put <a href=\"https://codex.wordpress.org/WordPress_Widgets\" rel=\"nofollow\">widgets</a> with countless features.</em></p>\n<p>Log in to your admin and go to Appearance>Widgets. If you don’t see the Widgets item, then your template hes no sidebars defined.<br />\nHow to <a href=\"https://codex.wordpress.org/Function_Reference/register_sidebar\" rel=\"nofollow\">register sidebar</a>.</p>\n</p>\n<h4>What do you suggest?</h4>\n<p>\n<p>What I do is, that I register sidebars at least one per logical block in the webdesign layout (template).<br />\nThen using 2046’s loop widget you can place the content loops anywhere you like and how many you like.<br />\nYou can interlace them by any other widgets. By drag & dropping the widgets into the dynamic sidebar areas you can easily define the structure of the whole website.</p>\n</p>\n<h4>What about design?</h4>\n<p>\n<p>If your template has the most basic CSS setups then you don’t have to wary. Widgets will nicely follow the actual template CSS rules and will obediently follow the predefined<br />\ndesign. If you still needs some exceptions for this or that widget or it’s element, every widget has it’s own CSS “id” or “class” so you can easily bend them to your needs.</p>\n</p>\n<h4>I do not see what I have expected to see.</h4>\n<p>\n<p>Well the widget is fairly complex.<br />\nCheck if the restrictions are not beating each other and also check if the content you expect there really is sortable the way you like it to be.<br />\nIf none of these checks works, then let me know on the <a href=\"https://wordpress.org/tags/2046s-widget-loops\" rel=\"nofollow\">forum</a>, I’ll do my best.</p>\n</p>\n<h4>Known bugs</h4>\n<p>\n<ul>\n<li>When you are in the widget setting in the part [elswhere]>[selected taxonomy] then the taxonomy fields are sometimes multiplied. This happens when always you drag&drop the widget.<br />\nDon’t wary this is just a Javascript skin effect. If you save the widget, or you come back next time, it will be fine. (I’m working on it).</li>\n</ul>\n</p>\n\n",
        "changelog": "<h4>2.253</h4>\n<ul>\n<li>NEW – Admin menu > Settings > 2046’s loop widget  – lets you switch the widget settings between normal mode and wide mode. More here http://o—-o.info/2065/rearrange-resort-widget-screen-in-wordpress/</li>\n</ul>\n<h4>2.252</h4>\n<ul>\n<li>Featured images are not rendred with the width and height in the img tag…. it plays much nicely if you build responsice layout \ud83d\ude09</li>\n</ul>\n<h4>2.251</h4>\n<ul>\n<li>NEW – Special widget (admin)</li>\n<li>NEW – widget notes (admin)</li>\n</ul>\n<h4>2.25</h4>\n<ul>\n<li>NEW switch for pagination (on/off)</li>\n<li>NEW user capabilities. You can select who can see the widget result.. based on WP roles</li>\n<li>FIX post number for Page types, is shown and working from now.</li>\n<li>FIX – cruicial fix for post types. From nowt recoignizes the post type correctly and applies the correct logic. (linear = post), (hierarchical = page).. or any other custom post types.</li>\n</ul>\n<h4>0.2474</h4>\n<ul>\n<li>fixed the “more” function for the content.. when you use the more tag and select in the widget to see the content, the content will by properly striped.</li>\n</ul>\n<h4>0.2473</h4>\n<ul>\n<li>the widget heading is Translation ready, meaning it is parsed by Gettext or if you have for example then it will go through : qTranslate and then Gettext</li>\n</ul>\n<h4>0.2472</h4>\n<ul>\n<li>Fix for empty filed for “selected ‘xxxxx’ IDs”, it shows nothing, but it schould show all. If empty no restriction are applied in this setting.</li>\n<li>Fix for last fix :), it really works now</li>\n<li>added – no restriction field in the category selection, so you can inactivate category constrains</li>\n</ul>\n<h4>0.2471</h4>\n<ul>\n<li>small fix for  NEW – IDs in “restrict to” is 3 possibilities</li>\n</ul>\n<h4>0.247</h4>\n<ul>\n<li>cache-able</li>\n<li>h4 added class</li>\n<li>navigation>link to category (change the arrow)</li>\n<li>widget sub-title fixed (admin widget panel)</li>\n<li>NEW – IDs in “restrict to” is 3 possibilities:\n<ol>\n<li>only on given IDs</li>\n<li>only on child pages of given id</li>\n<li>for these Ids and it’s children</li>\n</ol>\n</li>\n</ul>\n<h4>0.2461</h4>\n<ul>\n<li>no code changes, only the readme update plus new video showcase</li>\n<li>1/2 http://youtu.be/dU8Qll6Wqes</li>\n<li>2/2 http://youtu.be/wupAqsyLsF0</li>\n</ul>\n<h4>0.246</h4>\n<ul>\n<li>NEW – Gallery builder!</li>\n<li>NEW – h1-h5+span settings for titles</li>\n<li>NEW – added show/hide edit link</li>\n<li>NEW – html settings for titles</li>\n<li>NEW – ON/OFF title link</li>\n<li>NEW – show/hide edit link</li>\n<li>asmselect removed (the fancy taxonomy selector) until I find out how to implement it correctly</li>\n</ul>\n<h4>0.245</h4>\n<ul>\n<li>The image bellow the heading didn’t work : FIXED</li>\n</ul>\n<h4>0.244</h4>\n<p>[04.03.2012]</p>\n<ul>\n<li>localized (English, Czech) ready for more.</li>\n</ul>\n<h4>0.243</h4>\n<p>[03.03.2012]</p>\n<ul>\n<li>NEW ordering and it’s comparison paremetrs as well.</li>\n<li>NEW filter logic for custom meta and the logic parametrs too. For one custom meta “only”.</li>\n<li>The javascript is handled bit better, but still it’s not prefect ..see the Known bugs bellow.</li>\n</ul>\n<h4>0.242</h4>\n<ul>\n<li>the custom scafolding changed a bit. It doesn’t add redundant native widget div.</li>\n<li>also the navigation and the comments moved out of the widget div. This change should give you lot more freedom over their position, then when it was part of the widget scafold.</li>\n<li>added hard check for all imputs, you can’t write nonsense in the fields, or something that harms the result, or your layout \ud83d\ude09</li>\n<li>..under “selected taxonomy” is from now offset as well</li>\n<li>fixed typo in “taxonomy comparison” variable</li>\n</ul>\n<h4>0.241</h4>\n<p>[26.02.2012]</p>\n<ul>\n<li>when elsewhere>taxonomy was selected and no taxonomy was specified the “post number” didn’t work : FIXED</li>\n<li>edded Scafolding option</li>\n<li>image has now selector where you can choose if the image links to: post/page, image or nolink</li>\n<li>fixed edit links</li>\n<li>added classes to image links. General and also extra for each link type.</li>\n<li>Fixed bug for PAge types, when selected “by ID”</li>\n</ul>\n<h4>0.24</h4>\n<p>[22.02.2012]</p>\n<ul>\n<li>fixed pagination</li>\n<li>fixed navigation for pagination</li>\n<li>simplified Javascript</li>\n<li>added the restriction for number of posts/pages in [elsewhere]>[Selected taxonomy]. If the result returns more theb the number and some kind of navigation is ON, then the result will be paged.</li>\n</ul>\n<h4>0.23</h4>\n<p>[24.02.2012]</p>\n<ul>\n<li>the multiple select box for taxonomy types is now runned by the jquery-asmselect (you’ll love it if you have hundreds of tags )</li>\n<li>works paged</li>\n</ul>\n<h4>0.21</h4>\n<p>[24.02.2012]</p>\n<ul>\n<li>removed some forgotten echo calls</li>\n<li>the multiple select box has native size 5 rows from now</li>\n</ul>\n<h4>0.2</h4>\n<ul>\n<li>all 3 widgets where merged in to one widget</li>\n<li>the file structure of the plugin changed a lot, many files were deleted</li>\n<li>The old initial JavaScript problem is solved</li>\n<li>the CSS and JS are not hard coded in each widget but loads independently and only once</li>\n<li>The widget now finds even custom post types</li>\n<li>it finds custom taxonomies and build appropriate settings for them</li>\n<li>new navigation settings (Scribu’s Page Navi ready)</li>\n<li>and so on…</li>\n</ul>\n<h4>0.131</h4>\n<ul>\n<li>fixed typo</li>\n<li>added the page restriction</li>\n</ul>\n<h4>0.13</h4>\n<ul>\n<li>Post widget fixes : Div “beforewidget” won’t show up if the loop is empty, Disallow on ids can handle multiple ids.</li>\n<li>Page widget fixes : Disallow on ids can handle multiple ids, Added Prevention for being show on Page, post ids and template types.</li>\n<li>Recent widget removed</li>\n<li>Added Final loop widget: Briefly. It let’s you show Post or Pages anywhere. The widget let’s you allow or disallow the loop to be shown on certain places. Plus, you can show or hide comments and it’s form, show the author, list of categories and tags.</li>\n<li>When the user is logged in the “edit link” is present after the post/page title.</li>\n<li>A small note added in to all widgets: “To see the widget behave properly, when you drop the widget in here the widget should to be saved first.”</li>\n<li>In order to have a unique class which won’t interfere with other classes, comment_booble class has been changed from “comment_number” to “wl2046_comment_number”</li>\n</ul>\n<h4>0.12: 2012-02-07</h4>\n<ul>\n<li>UI fixes + added screenshot</li>\n</ul>\n<h4>0.11: 2012-02-07</h4>\n<p>Page widget:</p>\n<ul>\n<li>add show pages from the same hierarchy level</li>\n<li>add restrict to pages by ID(s)</li>\n</ul>\n<p>Post widget</p>\n<ul>\n<li>restrict to post ID(s)</li>\n<li>do not show on: Single post, home, Front Page, Archive, Tag/Term list, Taxonomy, Category list, Author’s list, Search, 404 error page</li>\n</ul>\n<p>Global face lift</p>\n<h4>0.1: 2012-02-05</h4>\n<ul>\n<li>Initial version</li>\n</ul>\n<h4>Known bugs</h4>\n<p>When you have multiple widgets where you filter the content by the taxonomies, than when you save some of these widgets the taxonomy selector is multiplied for other widget than the one you just saved ;(<br />\nThis is not a crucial bug, it wont brake anything it is just something I want to fix. If you know how, let me know.</p>\n<h4>Future plans</h4>\n<ul>\n<li>Drag&Drop content builder</li>\n<li>multiple custom meta comparison filter</li>\n</ul>\n<h4>Thanks</h4>\n<p>Thanks to Scribu for his WP Navi that I have “integrated” as one of the navigation settings in to the widget. And thanks to Sribu again. When I tried to find an answer for<br />\nall the uncommon problems it was his answer somewhere in the Interweb that helps me to find the solution. Thanks to you allyou are my source of knowledge.</p>\n",
        "screenshots": "<ol><li><a href=\"https://ps.w.org/2046s-widget-loops/trunk/screenshot-1.jpg?rev=1539087\"><img src=\"https://ps.w.org/2046s-widget-loops/trunk/screenshot-1.jpg?rev=1539087\" alt=\"Screenshot of the version 0.241\nMore on <a href="http://2046.cz/freestuff/2046s-loop-widget.html">http://2046.cz/freestuff/2046s-loop-widget.html</a>\"></a><p>Screenshot of the version 0.241\nMore on <a href=\"http://2046.cz/freestuff/2046s-loop-widget.html\">http://2046.cz/freestuff/2046s-loop-widget.html</a></p></li></ol>"
    },
    "description": "<p><span class=\"embed-youtube\" style=\"text-align:center; display: block;\"><iframe class='youtube-player' type='text/html' width='640' height='390' src='https://www.youtube.com/embed/dU8Qll6Wqes?version=3&rel=1&fs=1&autohide=2&showsearch=0&showinfo=1&iv_load_policy=1&wmode=transparent' allowfullscreen='true' style='border:0;'></iframe></span></p>\n<p>When you build the content with “2046’s loop widget”, the only thing you have to decide is what content you want to see and where. All the programming you always wanted to avoid is gone.<br />\nThe widget covers the most routinely used content logic. The aim of this widget is to speed up the process of content structuring and simplicity of usage while keeping the standards.</p>\n<h4>Note</h4>\n<p>I highly encourage you to use the “Easy” instead of 2046’s loop widget. <a href=\"https://wordpress.org/extend/plugins/easy/screenshots/\" rel=\"nofollow\">Easy</a> is a new version of 2046 loop widgets.  It’s is much more flexible and in active development.</p>\n<p>Why I made different Plugin of the same type?<br />\nWell some people use the 2046’s loop widget already and are “used to it”. Most importantly the Easy is totally different animal although with similar functions.</p>\n<p>“A picture better be worth a thousand words.” Don’t forget to check <a href=\"https://wordpress.org/extend/plugins/2046s-widget-loops/screenshots/\" rel=\"nofollow\">screenshots</a>.</p>\n<h4>Localization</h4>\n<ul>\n<li>English</li>\n<li>Czech</li>\n</ul>\n<h4>Compatibility</h4>\n<p>Tested with <a href=\"https://wordpress.org/extend/plugins/custom-content-type-manager/\" rel=\"nofollow\">CCTM</a>, <a href=\"More Types\" rel=\"nofollow\">More types</a>, <a href=\"https://wordpress.org/extend/plugins/more-taxonomies/\" rel=\"nofollow\">More taxonomies</a>, <a href=\"http://wpml.org/\" rel=\"nofollow\">WPML</a>.<br />\n<a href=\"https://wordpress.org/extend/plugins/wp-pagenavi/\" rel=\"nofollow\">WP-PageNavi</a> ready.<br />\n<a href=\"http://twitter.github.com/\" rel=\"nofollow\">Bootstrap</a> ready.</p>\n",
    "short_description": "2046's loop widget boosts you website prototyping.",
    "download_link": "https://downloads.wordpress.org/plugin/2046s-widget-loops.zip",
    "screenshots": {
        "1": {
            "src": "https://ps.w.org/2046s-widget-loops/trunk/screenshot-1.jpg?rev=1539087",
            "caption": "Screenshot of the version 0.241\nMore on <a href=\"http://2046.cz/freestuff/2046s-loop-widget.html\">http://2046.cz/freestuff/2046s-loop-widget.html</a>"
        }
    },
    "tags": {
        "admin": "admin",
        "loop": "loop",
        "page": "page",
        "post": "post",
        "widget": "widget"
    },
    "versions": [],
    "donate_link": "http://2046.cz/freestuff/2046s-loop-widget.html",
    "contributors": []
}

将其粘贴到JSON lint,您会看到问题与截图相关:

由于我无法更改API的响应,我想知道我是否有办法以编程方式清理它?我用Python做了提取。您可以在此处查看我用于处理API响应的代码: https://github.com/davidshq/wopas

0 个答案:

没有答案