Page tree

Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Added link to jsoncpp setup instructions


* You will need to have already done the required setup of jsoncpp in order to use follow this example (link to jsoncpp setup pending); see FireBreath Libraries for instructions on setting up jsoncpp

Code Block
#include "DOM/Window.h"


FB::variant yourPluginAPI::aMethodThatReturnsParsedVariants()

    creation of the VariantMap object here

    // Retrieve a reference to the DOM Window
    FB::DOM::WindowPtr window = m_host->getDOMWindow();

    // Check if the DOM Window has an in-built JSON Parser
    if (window && window->getJSObject()->HasProperty("JSON")) {
        // Convert the VariantMap to a Json::Value object
        Json::Value json_map = FB::variantToJsonValue(users_variant_map);

        // Create a writer that will convert the object to a string
        Json::FastWriter writer;

        // Create a reference to the browsers JSON utility
        FB::JSObjectPtr obj = window->getProperty<FB::JSObjectPtr>("JSON");

        // Return the result of the invocation of JSON.parse
        return obj->Invoke("parse", FB::variant_list_of(writer.write(json_map)));
    } else {
        // No browser JSON parser detected, falling back to return of an FB::variant object
        return users_variant_map;