欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

量化交易之WorderTrader篇 - 读取、解析 json文件

程序员文章站 2024-02-04 13:36:16
...
#include "../Share/JsonToVariant.hpp"
#include <iostream>

void tqz_jsonTest(char *jsonPath) {
    
    // 读取 json 文件内容
	string jsonContent;
	BoostFile::read_file_contents(jsonPath, jsonContent);
    
    // 输出 json 文件内容
	printf(jsonContent.c_str());

	rj::Document document;
	document.Parse(jsonContent.c_str());
	
	otp::WTSVariant* variant = WTSVariant::createObject();
	jsonToVariant(document, variant);
    
    // 查找 key 是否存在, 如果存在则输出;
	WTSVariant* basefiles = variant->get("basefiles"); // basefiles is key
	if (basefiles->get("session")) {
		printf(basefiles->getCString("session"));
	}

	system("pause");
	exit(0);
}



int main() {
    
    tqz_jsonTest("config.json");

    return 0;
}

相关标签: WonderTrader json