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


C++ JsonValue::toString方法代码示例

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


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

示例1: dumpJsonValue

static void dumpJsonValue(const JsonValue& val) {
	static int level = 0;
	level++;
	assert(level < 10);
	if(const JsonArray* arr = val.toArray()) {
		printf("[");
		//printf("%p", arr);
		for(size_t i=0; i<arr->size(); i++) {
			if(i != 0)
				printf(", ");
			dumpJsonValue((*arr)[i]);
		}
		printf("]");
	} else if(const JsonObject* obj = val.toObject()) {
		printf("{%p", obj);
#if 0
		for(JsonObject::iterator itr = obj->begin(); itr != obj->end(); ++itr) {
			if(itr != obj->begin())
				printf(", ");
			printf("%s:", itr->first.c_str());
			dumpJsonValue(*itr->second);
		}
#endif
		printf("}");
	} else {
		printf("%s", val.toString().c_str());
	}
	level--;
}
开发者ID:Masken3,项目名称:wowfoot,代码行数:29,代码来源:import.cpp

示例2: OnData

    void OnData(
        const happyhttp::Response* r,
        void* userdata,
        const unsigned char* data,
        int n
        )
    {
        std::cout << "reading...\n";

        char *endptr;
        JsonValue value;
        JsonAllocator allocator;
        JsonParseStatus status = jsonParse((char*)data, &endptr, &value, allocator);
        if (status != JSON_PARSE_OK) {
            fprintf(stderr, "error at %zd, status: %d\n", endptr - (char*)data, status);
            exit(EXIT_FAILURE);
        } else { // SUCCESS
            switch (value.getTag()) {
            case JSON_TAG_NUMBER:
                printf("%g\n", value.toNumber());
                break;
            case JSON_TAG_BOOL:
                printf("%s\n", value.toBool() ? "true" : "false");
                break;
            case JSON_TAG_STRING:
                printf("\"%s\"\n", value.toString());
                break;
            case JSON_TAG_ARRAY:
                for (auto i : value) {
                    auto bleh = i->value;
                }
                break;
            case JSON_TAG_OBJECT:
                for (auto i : value) {
                    printf("%s = ", i->key);
                }
                break;
            case JSON_TAG_NULL:
                printf("null\n");
                break;
            }
        }
    }
开发者ID:ActionReaction,项目名称:ifttt-engine,代码行数:43,代码来源:arp.cpp

示例3: GenStat

static void GenStat(Stat& stat, const JsonValue& v) {
    switch (v.getTag()) {
    case JSON_ARRAY:
        for (auto const& i : v) {
            GenStat(stat, i->value);
            stat.elementCount++;
        }
        stat.arrayCount++;
        break;

    case JSON_OBJECT:
        for (auto const& i : v) {
            GenStat(stat, i->value);
            stat.memberCount++;
            stat.stringLength += strlen(i->key);
            stat.stringCount++;   // Key
        }
        stat.objectCount++;
        break;

    case JSON_STRING: 
        stat.stringCount++;
        stat.stringLength += strlen(v.toString());
        break;

    case JSON_NUMBER:
        stat.numberCount++;
        break;

    case JSON_TRUE:
        stat.trueCount++;
        break;

    case JSON_FALSE:
        stat.falseCount++;
        break;

    case JSON_NULL:
        stat.nullCount++;
        break;
    }
}
开发者ID:Lyoko-Jeremie,项目名称:nativejson-benchmark,代码行数:42,代码来源:gasontest.cpp

示例4: printReturn

void NewsScene::printReturn(JsonValue o)
{
    switch (o.getTag())
    {
        case JSON_TAG_NUMBER:
            printf("%g\n", o.toNumber());
            //sum += o.toNumber();
            break;
        case JSON_TAG_BOOL:
            printf("%s\n", o.toBool() ? "true" : "false");
            break;
        case JSON_TAG_STRING:
        {
            string theValue =o.toString();
            setValue(theValue);
        }
            break;
        case JSON_TAG_ARRAY:
            for (auto i : o)
            {
               // tmpNews = new News();
                listNews.push_back(new News());
                printReturn(i->value);
            }
            
            break;
        case JSON_TAG_OBJECT:
            for (auto i : o)
            {
                printf("%s = ", i->key);
                lastKey = i->key;
                printReturn(i->value);
            }
            break;
        case JSON_TAG_NULL:
            printf("null\n");
            break;
    }
}
开发者ID:rossimrc,项目名称:AlbertEinstein,代码行数:39,代码来源:NewsScene.cpp

示例5: dumpValue

static void dumpValue(std::ostringstream& os, const JsonValue& o, int shiftWidth, const std::string& linefeed = "", int indent = 0) {
    switch (o.getTag()) {
    case JSON_NUMBER:
        char buffer[32];
        sprintf(buffer, "%f", o.toNumber());
        os << buffer;
        break;
    case JSON_TRUE:
        os << "true";
        break;        
    case JSON_FALSE:
        os << "false";
        break;
    case JSON_STRING:
        dumpString(os, o.toString());
        break;
    case JSON_ARRAY:
        // It is not necessary to use o.toNode() to check if an array or object
        // is empty before iterating over its members, we do it here to allow
        // nicer pretty printing.
        if (!o.toNode()) {
            os << "[]";
            break;
        }
        os << "[" << linefeed;
        for (auto i : o) {
            if (shiftWidth > 0)
                os << std::setw(indent + shiftWidth) << " " << std::setw(0);
            dumpValue(os, i->value, shiftWidth, linefeed, indent + shiftWidth);
            if (i->next)
                os << ",";
            os << linefeed;
        }
        if (indent > 0)
            os << std::setw(indent) << " " << std::setw(0);
        os.put(']');
        break;
    case JSON_OBJECT:
        if (!o.toNode()) {
            os << "{}";
            break;
        }
        os << "{" << linefeed;
        for (auto i : o) {
            if (shiftWidth > 0)
                os << std::setw(indent + shiftWidth) << " " << std::setw(0);
            dumpString(os, i->key);
            os << ":";
            dumpValue(os, i->value, shiftWidth, linefeed, indent + shiftWidth);
            if (i->next)
                os << ",";
            os << linefeed;
        }
        if (indent > 0)
            os << std::setw(indent) << " " << std::setw(0);
        os.put('}');
        break;
    case JSON_NULL:
        os << "null";
        break;
    }
}
开发者ID:Lyoko-Jeremie,项目名称:nativejson-benchmark,代码行数:62,代码来源:gasontest.cpp


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