当前位置: 首页>>代码示例>>C++>>正文


C++ BSONElement::jsonString方法代码示例

本文整理汇总了C++中BSONElement::jsonString方法的典型用法代码示例。如果您正苦于以下问题:C++ BSONElement::jsonString方法的具体用法?C++ BSONElement::jsonString怎么用?C++ BSONElement::jsonString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BSONElement的用法示例。


在下文中一共展示了BSONElement::jsonString方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: csvString

    // Gets the string representation of a BSON object that can be correctly written to a CSV file
    string csvString (const BSONElement& object) {
        const char* binData; // Only used with BinData type

        switch (object.type()) {
        case MinKey:
            return "$MinKey";
        case MaxKey:
            return "$MaxKey";
        case NumberInt:
        case NumberDouble:
        case NumberLong:
        case Bool:
            return object.toString(false);
        case String:
        case Symbol:
            return csvEscape(object.toString(false), true);
        case Object:
            return csvEscape(object.jsonString(Strict, false));
        case Array:
            return csvEscape(object.jsonString(Strict, false));
        case BinData:
            int len;
            binData = object.binDataClean(len);
            return toHex(binData, len);
        case jstOID:
            return "ObjectID(" + object.OID().toString() + ")"; // OIDs are always 24 bytes
        case Date:
            return timeToISOString(object.Date() / 1000);
        case Timestamp:
            return csvEscape(object.jsonString(Strict, false));
        case RegEx:
            return csvEscape("/" + string(object.regex()) + "/" + string(object.regexFlags()));
        case Code:
            return csvEscape(object.toString(false));
        case CodeWScope:
            if (string(object.codeWScopeScopeDataUnsafe()) == "") {
                return csvEscape(object.toString(false));
            } else {
                return csvEscape(object.jsonString(Strict, false));
            }
        case EOO:
        case Undefined:
        case DBRef:
        case jstNULL:
            cerr << "Invalid BSON object type for CSV output: " << object.type() << endl;
            return "";
        }
        // Can never get here
        verify(false);
        return "";
    }
开发者ID:abhishekkumar1989,项目名称:mongo,代码行数:52,代码来源:export.cpp

示例2: jsonString

string BSONObj::jsonString( JsonStringFormat format, int pretty, bool isArray ) const {

    if ( isEmpty() ) return isArray ? "[]" : "{}";

    StringBuilder s;
    s << (isArray ?  "[ " : "{ ");
    BSONObjIterator i(*this);
    BSONElement e = i.next();
    if ( !e.eoo() )
        while ( 1 ) {
            s << e.jsonString( format, !isArray, pretty?pretty+1:0 );
            e = i.next();
            if ( e.eoo() )
                break;
            s << ",";
            if ( pretty ) {
                s << '\n';
                for( int x = 0; x < pretty; x++ )
                    s << "  ";
            }
            else {
                s << " ";
            }
        }
    s << (isArray ? " ]" : " }");
    return s.str();
}
开发者ID:kingfs,项目名称:tokumxse,代码行数:27,代码来源:bsonobj.cpp

示例3: jsonString

    string BSONObj::jsonString( JsonStringFormat format, int pretty ) const {

        if ( isEmpty() ) return "{}";

        stringstream s;
        s << "{ ";
        BSONObjIterator i(*this);
        BSONElement e = i.next();
        if ( !e.eoo() )
            while ( 1 ) {
                s << e.jsonString( format, true, pretty?pretty+1:0 );
                e = i.next();
                if ( e.eoo() )
                    break;
                s << ",";
                if ( pretty ) {
                    s << '\n';
                    for( int x = 0; x < pretty; x++ )
                        s << "  ";
                }
                else {
                    s << " ";
                }
            }
        s << " }";
        return s.str();
    }
开发者ID:erickt,项目名称:mongo,代码行数:27,代码来源:jsobj.cpp

示例4: jsonString

    string BSONObj::jsonString( JsonStringFormat format ) const {

        if ( isEmpty() ) return "{}";

        stringstream s;
        s << "{ ";
        BSONObjIterator i(*this);
        BSONElement e = i.next();
        if ( !e.eoo() )
            while ( 1 ) {
                s << e.jsonString( format );
                e = i.next();
                if ( e.eoo() )
                    break;
                s << ", ";
            }
        s << " }";
        return s.str();
    }
开发者ID:agiamas,项目名称:mongo,代码行数:19,代码来源:jsobj.cpp


注:本文中的BSONElement::jsonString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。