Bootstrap

read json

// parse json from string.
    using rapidjson::Document ;
    Document doc ;
    doc .Parse< 0>(stringFromStream .c_str()) ;
    if (doc .HasParseError()) {
        rapidjson::ParseErrorCode code = doc .GetParseError() ;
        psln(code) ;
        return ;
    }

    // use values in parse result.
    using rapidjson::Value ;
    Value & v = doc[ "dictVersion"] ;
    if (v .IsInt()) {
        psln(v .GetInt()) ;
    }

    Value & contents = doc[ "content"] ;
    if (contents .IsArray()) {
        for (size_t i = 0 ; i < contents.Size(); ++i) {
            Value & v = contents[i] ;
            assert(v .IsObject()) ;
            if (v .HasMember( "key") && v[ "key"] .IsString()) {
                psln(v[ "key"] .GetString()) ;
            }
            if (v .HasMember( "value") && v[ "value"] .IsString()) {
                psln(v[ "value"] .GetString()) ;
            }
        }
    }
;