WordPress.org

Ready to get started?Download WordPress

Forums

JSON API
invalid json format (H) (9 posts)

  1. 10mitri
    Member
    Posted 9 months ago #

    Hi,
    when I try to retrieve blog posts, json format is invalid with html tags at the beginning ex: http://myblog.com/?json = get_recent_posts
    => <div ...> {"status":"ok","count":8,

    By cons when I recovered only categories the json is valid.
    ex: http://myblog.com/?json = get_category_index

    Is there a way to clean the json to remove the html code at the beginning of my json?

    thank you

    http://wordpress.org/plugins/json-api/

  2. Bob Gregor
    Member
    Posted 9 months ago #

    switch to a default WordPress theme, if that doesn't fix, disable one plugin at a time, until you find the error.

    Basically, something is outputting content when it should not.

  3. 10mitri
    Member
    Posted 9 months ago #

    In fact, the problem is caused by the theme.

    Is it possible to keep this theme and change something in the code of the theme to detect that I use the API?

  4. dphiffer
    Member
    Plugin Author

    Posted 9 months ago #

    Which theme is it?

  5. 10mitri
    Member
    Posted 9 months ago #

    It's BOLD NEWS Theme 1.1.5
    You can find it in the WooFramework version 5.5.0.

    Thank you for your help!

  6. Bob Gregor
    Member
    Posted 8 months ago #

    just thinking off the top of my head (at 11pm on a Friday)....

    First of all - for this to work - I'd disable the "pretty JSON API url" and just use a GET parameter, I.E. ?json=get_recent_posts

    then, I'd edit my functions.php and add this

    function remove_all_theme_output ()
    {
        remove_all_actions('wp_head');
        remove_all_actions('wp_footer');
        remove_all_actions('template_redirect');
    }
    if (isset($_GET['json'])) {
        add_action('init', 'remove_all_theme_output');
    }

    Keep in mind that this is a very hacky approach... I'd much prefer to find where that stray <div> is coming from. Have you edited the theme files? Have you reinstalled the theme from source? Also, are you using Child Themes?

    Finding that stray div also has the added benefit of fixing broken markup on your site. One <div> to rule them all....muhahaha

  7. 10mitri
    Member
    Posted 8 months ago #

    Bob thank you for your help,
    I didn't test your code but the problem is not related to the theme but by the pluggin "Really Simple Facebook Twitter share buttons".
    He added "div" at the beginning of each post like this:

    <div style="min-height:33px;" class="really_simple_share really_simple_share_button robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:80px;">...

    By disabling the pluggin I have no problem. I'll try to find another way to share posts. Maybe another pluggin?

    Thank you Bob

  8. Bob Gregor
    Member
    Posted 7 months ago #

    Contact that plugin author about the problem, they're probably doing something the wrong WordPress API way. The other option to fix it (now that you've narrowed down the source) is to install the DebugBar http://wordpress.org/plugins/debug-bar/ then add the actions and filters addon: http://wordpress.org/plugins/debug-bar-actions-and-filters-addon/

    Once you have those installed - you should be able to search for the function name that's adding the <div style="min-height:33px;" class="really_simple_share really_simple_share_button robots-nocontent snap_nopreview"><div class="really_simple_share_facebook_like" style="width:80px;"> and remove it by checking if isset($_GET['json'])

    Off the top of my head - they're probably adding the content by filtering "the_content" http://adambrown.info/p/wp_hooks/hook/the_content

  9. cdwamina
    Member
    Posted 7 months ago #

    The Google QPX Express API uses REST and JSON to return data. Will your plugin help in integrating this API with my Word Press Template? I am working on building a travel website and this API is designed for the purpose, but is having some difficulties in integrating the API with word press to allow it to work as descriped. The goal is to have the interface look similar to the website Hotwire.com, Cheaptickets, etc. The client is in the travel agency business and wants to start his own website. Please help!

Reply

You must log in to post.

About this Plugin

About this Topic