jsoncpp vc2005 编译测试
2010-03-17 14:58
555 查看
新建一个vc8 win32 控制台程序
使用多字节字符
包含jsoncpp_src_0_5_0/src/lib_json 下的所有代码到工程中
引用jsoncpp_src_0_5_0/include/json/json.h
编写如下代码:
// test_jsoncpp_vc8.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include "../../include/json/json.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string doc;
doc = "{ /"encoding/" : /"UTF-8/" }";
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( doc, root );
if ( !parsingSuccessful )
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration/n"
<< reader.getFormatedErrorMessages();
return 0;
}
// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
// such member.
std::string encoding;
encoding = root.get("encoding", "UTF-8" ).asString();
// Get the value of the member of root named 'encoding', return a 'null' value if
// there is no such member.
/*
const Json::Value plugins = root["plug-ins"];
for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
loadPlugIn( plugins[index].asString() );
setIndentLength( root["indent"].get("length", 3).asInt() );
setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
*/
// ...
// At application shutdown to make the new configuration document:
// Since Json::Value has implicit constructor for all value types, it is not
// necessary to explicitly construct the Json::Value object:
root["encoding"] = "GB2312";
root["indent"]["length"] = 2;
root["indent"]["use_space"] = 5;
Json::StyledWriter writer;
// Make a new JSON document for the configuration. Preserve original comments.
std::string outputConfig = writer.write( root );
// You can also use streams. This will put the contents of any JSON
// stream at a particular sub-value, if you'd like.
//std::cin >> root["subtree"];
root["subtree"] = "日";
// And you can write to a stream, using the StyledWriter automatically.
std::cout << root;
getchar();
return 0;
}
运行结果:
{
"encoding" : "GB2312",
"indent" :
{
"length" : 2,
"use_space" : 5
},
"subtree" : "日"
}
使用多字节字符
包含jsoncpp_src_0_5_0/src/lib_json 下的所有代码到工程中
引用jsoncpp_src_0_5_0/include/json/json.h
编写如下代码:
// test_jsoncpp_vc8.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include <iostream>
#include "../../include/json/json.h"
int _tmain(int argc, _TCHAR* argv[])
{
std::string doc;
doc = "{ /"encoding/" : /"UTF-8/" }";
Json::Value root; // will contains the root value after parsing.
Json::Reader reader;
bool parsingSuccessful = reader.parse( doc, root );
if ( !parsingSuccessful )
{
// report to the user the failure and their locations in the document.
std::cout << "Failed to parse configuration/n"
<< reader.getFormatedErrorMessages();
return 0;
}
// Get the value of the member of root named 'encoding', return 'UTF-8' if there is no
// such member.
std::string encoding;
encoding = root.get("encoding", "UTF-8" ).asString();
// Get the value of the member of root named 'encoding', return a 'null' value if
// there is no such member.
/*
const Json::Value plugins = root["plug-ins"];
for ( int index = 0; index < plugins.size(); ++index ) // Iterates over the sequence elements.
loadPlugIn( plugins[index].asString() );
setIndentLength( root["indent"].get("length", 3).asInt() );
setIndentUseSpace( root["indent"].get("use_space", true).asBool() );
*/
// ...
// At application shutdown to make the new configuration document:
// Since Json::Value has implicit constructor for all value types, it is not
// necessary to explicitly construct the Json::Value object:
root["encoding"] = "GB2312";
root["indent"]["length"] = 2;
root["indent"]["use_space"] = 5;
Json::StyledWriter writer;
// Make a new JSON document for the configuration. Preserve original comments.
std::string outputConfig = writer.write( root );
// You can also use streams. This will put the contents of any JSON
// stream at a particular sub-value, if you'd like.
//std::cin >> root["subtree"];
root["subtree"] = "日";
// And you can write to a stream, using the StyledWriter automatically.
std::cout << root;
getchar();
return 0;
}
运行结果:
{
"encoding" : "GB2312",
"indent" :
{
"length" : 2,
"use_space" : 5
},
"subtree" : "日"
}
相关文章推荐
- 使用C++处理JSON数据交换格式,附已经VC2005编译好的静态lib库
- linux下jsoncpp的编译和测试使用
- vs2010 vc jsoncpp 编译要点
- Visual Studio 中 VC++/MFC 下 jsoncpp 静态库的编译和引用
- VC2005 + SQLite 3.6.3 编译、测试开发手记
- VC2005 + SQLite 3.6.3 编译、测试开发手记
- linux下jsoncpp的编译和测试使用
- 关于在VC工程中接入jsonCpp的lib报LINK 2005解决方法
- C++ 解析Json VC6 中编译、使用jsoncpp
- VC编译错误:uafxcw.lib(afxmem.obj) : error LNK2005: "void * __cdecl operator new(unsigned int)" (??2@YAPA
- linux C++程序使用jsoncpp,并编译程序
- Linux下编译Jsoncpp
- VC2005多配置工程中跳过部分文件不编译
- jsoncpp在vs2013下的安装以及静态连接错误error LNK2005问题
- VC++ 2005中编译C出错:error C2143: syntax error : missing ';' before 'type'
- 关于vc2005编译asm文件出错的一个处理方法
- VC 2005 下如何编译安装qt
- VC2005编译错误:error C2146: 语法错误 : 缺少“;”(在标识符“PVOID...
- VC 2005 下如何编译安装并开发 QT 4.4.0 应用程序 (转)
- Jsoncpp在linux中的安装、编译及其简单应用