Json   发布时间:2022-04-22  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了jsoncpp vc2005 编译测试大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

新建一个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 << "@L_262_3@ 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 vc2005 编译测试全部内容,希望文章能够帮你解决jsoncpp vc2005 编译测试所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。