Exemplo n.º 1
0
static void testJSON()
{
    static const char text[] =
        "{\"a\" : \"me\", \"b\" : false, \"c\" : 12.3, \"d\" : 123 }";

    MemoryInputStream stream(reinterpret_cast<const unsigned char *>(&text[0]), sizeof text);

    Reader json;

    if ( json.open(&stream) && json.beginObject() )
    {
        std::string value;
        bool bValue = false;
        double fValue = 0.f;
        long iValue = 0;
        if ( json.namedValue("a", value) &&
                json.namedValue("b", bValue) &&
                json.namedValue("c", fValue) &&
                json.namedValue("d", iValue) &&
                json.endObject() )
        {
            puts("pass");
        }
        else
        {
            puts("fail");
        }
    }
}