1. #include <iostream>
  2. //#include "json/json.h"
  3. #include "json_reader.cpp"
  4. #include "json_value.cpp"
  5. #include "json_writer.cpp"
  6. using namespace std;
  7. using namespace Json;
  8. int main(int argc, char *argv[])
  9. {
  10. // Configuration options
  11. char *config_doc=" { \"encoding\" :\"UTF-8\",\"plug-ins\" : [\"python\",\"c++\",\"ruby\"],\"indent\" : { \"length\" : 3, \"use_space\": true }}";
  12. Json::Value root;   // will contains the root value after parsing.
  13. Json::Reader reader;
  14. bool parsingSuccessful = reader.parse( config_doc, root );
  15. if ( !parsingSuccessful )
  16. {
  17. // report to the user the failure and their locations in the document.
  18. std::cout  << "Failed to parse configuration\n"
  19. << reader.getFormattedErrorMessages();
  20. return 1;
  21. }
  22. reader.parse(config_doc,root,false);     //解析出json放到json中
  23. std::string encoding = root.get("encoding", "GBK" ).asString();
  24. const Json::Value plugins = root["plug-ins"];
  25. for(int index = 0; index < plugins.size(); ++index ){
  26. cout<<plugins[index];
  27. }
  28. cout<< plugins;
  29. cout<<encoding<<endl;
  30. root["encoding"] = "GB2312";
  31. root["indent"]["length"] =  5;
  32. root["indent"]["use_space"] = false;
  33. Json::StyledWriter writer;
  34. std::string outputConfig = writer.write( root );
  35. cout<<outputConfig;
  36. system("PAUSE");
  37. return 0;
  38. }

jsoncpp操作 json的更多相关文章

  1. JsonCpp操作数组对象

    JsonCpp操作数组对象 概述 ​ Json格式数据中,除了简单的String类型和一些非String类型,也有像各种高级语言中的数组类型一般的数组对象,且Json数组在实际开发中使用频率也比较高, ...

  2. 基于开源库jsoncpp的json字符串解析

    json(JavaScript Object Notation)是一种轻量级高效数据交换格式.相比于XML,其更加简洁,解析更加方便.在实习期间,我负责的程序模块,多次使用到json进行数据传输.由于 ...

  3. 让C#可以像Javascript一样操作Json

    Json的简介 JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式.它基于ECMAScript的一个子集. JSON采用完全独立于语言的文本格式,但是也使用了 ...

  4. JavaScript操作JSON的方法总结,JSON字符串转换为JSON对象

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...

  5. C# 技巧(3) C# 操作 JSON

    RestAPI中, 经常需要操作json字符串,  需要把json字符串"反序列化"成一个对象, 也需要把一个对象"序列化"成一字符串. C# 操作json, ...

  6. JS操作JSON总结

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...

  7. C#操作JSON

    http://www.cnblogs.com/LiZhiW/p/3624729.html C#操作JSON 1. .NET对JSON的支持介绍............................. ...

  8. JSON和GSON操作json数据

    1,JSON操作json import net.sf.json.JSONArray; import net.sf.json.JSONObject; //json操作数据 public static S ...

  9. js之操作JSON数据

    JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...

随机推荐

  1. C++学习笔记24:makefile文件

    makefile make命令:负责c/c++程序编译与链接 make根据指定命令进行建构 建构规则文件:GNUmakefile , makefile,Makefile makefile 文件格式 m ...

  2. HC系列蓝牙模块连接单片机与电脑,传输数据(蓝牙心电测试)

    毕设做无线心电监护.有线的做出来了,AD8232+MCU+LabVIEW上位机.pcb还没时间搞,这个9*7*2.5cm拿来测试能用. 自己做了AD8232的模拟前端,打的板子还没到没法测试. 虽然比 ...

  3. Neo4j Cypher运行示例

    示例来源: Neo4j in Action. 0 准备数据 0.1 node (user1 { name: 'John Johnson', type: 'User', email: 'jsmith@e ...

  4. 构建一个简单的WCF应用——WCF学习笔记(1)

    通过<WCF全面解析>来知识分享....感谢蒋金楠老师@Artech 一.VS中构建解决方案   Client一个控制台程序模拟的客户端,引用Service.ServiceModel.dl ...

  5. html随记

    姓名输入框:<input type="text" value="默认有值"/> 密码输入框:<input type="text&qu ...

  6. ExtAspNet和FineUI未将对象引用设置到对象的实例

    要在web.config中加入 <configSections> <section name="ExtAspNet" type="ExtAspNet.C ...

  7. selenium之xpath定位和input文本

    selenium之xpath定位和input文本 xpath简单定位: 打开浏览器的F12 在自己需要定位的元素的那里右键 选择copy->xpath selenium获取input下的文本: ...

  8. MapReduce的输入输出

    mapper和reducer的划分 mapper的数量等于输入文件被划分成的分块数,这取决于输入文件的大小以及文件块的大小.一个map操作只处理一个输入分片.运行作业的客户端通过调用getSplits ...

  9. java的读文件操作

    java读取文件内容,可以作如下理解: 首先获得一个文件句柄,File file = new File():file即为文件句柄.两人之间联通电话网络了,就可以开始打电话了. 通过这条线路读取甲方的信 ...

  10. Cannot find executable for CFBundle 解决办法

    出错日志为:2013-12-29 01:17:49.785 Displaying Alerts with UIAlertView[419:70b] Cannot find executable for ...