- HOME
- Post in | and so on
- Post at | 2012. 7. 19. 13:46 | by 밀크빵.
- View comment
JSONcpp lib 추가할때 메인함수 (에러 남 링크에러.. 결국 헤더파일이랑 소스 파일만 추가해서(라이브러리 제외) 사용 ㅠㅠ)
// json_test.cpp : 응용 프로그램에 대한 진입점을 정의합니다.
//
#include "stdafx.h"
#include "json_test.h"
#include "json.h"
#include <string>
#include <iostream>
#pragma comment(lib, "json_vc71_libmtd.lib")
int main(int argc, char ** argv)
{
std::string jsonStr = "{ \
\"encoding\" : \"UTF-8\", \
\"plug-ins\": \
[\"python\", \
\"c++\", \
\"ruby\"], \
\"indent\" : \
{\"length\" : 3, \
\"use_space\":true } \
}";
Json::Value root;
Json::Reader reader;
bool parsingSuccessful = reader.parse(jsonStr,root);
if(!parsingSuccessful)
{
std::cout << "Failed to parse configuration \n" << reader.getFormatedErrorMessages();
return -1;
}
std::cout << "jsoncpp has been ready to work" << std::endl;
std::string strEncoding = root.get("encoding", "UTF-8").asString();
std::cout<<"[Encoding] : "<<strEncoding <<std::endl;
std ::string strPlugin;
const Json::Value plugins = root["plug-ins"];
for(int index = 0; index <plugins.size(); ++index)
{
strPlugin = plugins[index].asString();
std::cout <<"[plugin] : " <<strPlugin <<std::endl;
}
std::cout << "[Indent Length] :"<<root["indent"].get("length",100).asInt()<<std::endl;
std::cout << "[Indent Use Space]: "<<root["indent"].get("length",100).asBool()<<std::endl;
return 0;
}