#include <iostream>
#include "Poco/Dynamic/Var.h"
#include "Poco/Dynamic/Pair.h"
#include "Poco/Dynamic/VarIterator.h"
#include "Poco/JSON/Array.h"
#include <vector>
#include <map>
#include "Poco/JSON/Parser.h" using Poco::Dynamic::Var;
using Poco::JSON::Parser;
using Poco::Dynamic::Pair;
using Poco::JSON::Array;
using Poco::JSON::Object; int main(int argc, const char * argv[]) {
using namespace std;
Poco::JSON::Object scores;
scores.set("数学", );
scores.set("英语", );
scores.set("语文", );
scores.set("化学", );
scores.set("物理", );
scores.set("生物", );
Poco::JSON::Object student;
student.set("name", "小南");
student.set("address", "四川省成都市锦江区锦华路一段7号爱家丽苑1栋1单元305室");
student.set("class", "四川省成都市第七中学2010级2班");
student.set("grade", Poco::Dynamic::Var(scores));
Poco::Dynamic::Var JSON(student);
cout << JSON.toString() << endl;
string theJSON = JSON.toString();
Poco::JSON::Parser parser;
Poco::Dynamic::Var json = parser.parse(theJSON);
Poco::JSON::Object theObj = *json.extract<Poco::JSON::Object::Ptr>();
Poco::Dynamic::Var theScores = theObj.get("grade");
Poco::Dynamic::Var name = theObj.get("name");
Poco::Dynamic::Var address = theObj.get("address");
Poco::Dynamic::Var theClass = theObj.get("class");
Poco::JSON::Object grade = *theScores.extract<Poco::JSON::Object::Ptr>();
Poco::Dynamic::Var math = grade.get("数学");
Poco::Dynamic::Var english = grade.get("英语");
Poco::Dynamic::Var chinese = grade.get("语文");
Poco::Dynamic::Var wuli = grade.get("物理");
Poco::Dynamic::Var shengwu = grade.get("生物");
Poco::Dynamic::Var huaxue = grade.get("化学");
cout << "\n\n姓名: " << name.toString() << endl
<< "班级: " << theClass.toString() << endl
<< "地址: " << address.toString() << endl
<< "数学: " << math.convert<int>() << endl
<< "语文: " << chinese.convert<int>() << endl
<< "化学: " << huaxue.convert<int>() << endl
<< "物理: " << wuli.convert<int>() << endl
<< "生物: " << shengwu.convert<int>() << endl;
return ;
} 输出结果:
{
"address" : "四川省成都市锦江区锦华路一段7号爱家丽苑1栋1单元305室",
"class" : "四川省成都市第七中学2010级2班",
"grade" : {
"化学" : ,
"数学" : ,
"物理" : ,
"生物" : ,
"英语" : ,
"语文" :
},
"name" : "小南"
} 姓名: 小南
班级: 四川省宣汉中学2010级2班
地址: 四川省成都市锦江区锦华路一段7号爱家丽苑1栋1单元305室
数学:
语文:
化学:
物理:
生物:

Poco C++——JSON解析的更多相关文章

  1. Android okHttp网络请求之Json解析

    前言: 前面两篇文章介绍了基于okHttp的post.get请求,以及文件的上传下载,今天主要介绍一下如何和Json解析一起使用?如何才能提高开发效率? okHttp相关文章地址: Android o ...

  2. Json解析工具的选择

    前言 前段时间@寒江不钓同学针对国内Top500和Google Play Top200 Android应用做了全面的分析(具体分析报告见文末的参考资料),其中有涉及到对主流应用使用json框架Gson ...

  3. iOS json 解析遇到error: Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed.

    Error Domain=NSCocoaErrorDomain Code=3840 "The operation couldn’t be completed. (Cocoa error 38 ...

  4. Android之JSON解析

    做个Android网络编程的同学一定对于JSON解析一点都不陌生,因为现在我们通过手机向服务器请求资源,服务器给我们返回的数据资源一般都是以JSON格式返回,当然还有一些通过XML格式返回,相对JSO ...

  5. Android总结之json解析(FastJson Gson 对比)

    前言: 最近为了统一项目中使用的框架,发现项目中用到了两种json解析框架,他们就是当今非常主流的json解析框架:google的Gson 和阿里巴巴的FastJson,为了废除其中一个所以来个性能和 ...

  6. JSON解析和XML解析对比

    JSON解析和XML解析是较为普遍的两种解析方式,其中JSON解析的市场分额更大.本文系统的分析两种解析方式的区别,为更好地处理数据作准备.由于目前阶段主要是做移动开发,所以本文所描述的JSON解析和 ...

  7. iOS json解析的几种方法 NSJSONSerialization,JSONKit,SBJson ,TouchJson

    相关的第三方类库大家可以去github上下载 1.NSJSONSerialization 具体代码如下 : - (void)viewDidLoad { [super viewDidLoad]; NSD ...

  8. Json解析工具Jackson(使用注解)

    原文http://blog.csdn.net/nomousewch/article/details/8955796 接上一篇文章Json解析工具Jackson(简单应用),jackson在实际应用中给 ...

  9. Json解析工具Jackson(简单应用)

    原文http://blog.csdn.net/nomousewch/article/details/8955796 概述 Jackson库(http://jackson.codehaus.org),是 ...

随机推荐

  1. 修改sql2005字段

    alter table 表名 add 字段名 数据类型 default 默认值 增加:alter table AdCategory ADD SEOTitleNo varchar(50); 删除:ALT ...

  2. 【转】使用JDK自带jvisualvm监控tomcat

    转载地址: http://my.oschina.net/kone/blog/157239 jdk自带有个jvisualvm工具.该工具是用来监控java运行程序的cpu.内存.线程等的使用情况.并且使 ...

  3. mini.open打开窗口时传递参数

    mini.open({ url: "xxx.html", showMaxButton: false, allowResize: false, title: '标题', width: ...

  4. hdu4940 Destroy Transportation system(2014多校联合第七场)

    题意很容易转化到这样的问题:在一个强连通的有向图D中是否存在这样的集合划分S + T = D,从S到T集合的边权大于从T到S集合的边权. 即D(i, j)  > B(j, i) + D(j, i ...

  5. Shopping(SPFA+DFS HDU3768)

    Shopping Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  6. Accepted Necklace

    Accepted Necklace Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) T ...

  7. Unity中HDR外发光的使用

    1.使用标准材质,设置好Emission外发光 2.Camera下打开HDR,加上Bloom特效 最终效果 如果只勾选HDR,只会有高光感,不会有外发光 注意,正向光照下打开HDR不可用抗锯齿,否则切 ...

  8. malloc与kmalloc

    在设备驱动程序中动态开辟内存,不是用malloc,而是kmalloc,或者用get_free_pages直接申请页.释放内存用的是kfree,或free_pages. 对于提供了MMU(存储管理器,辅 ...

  9. 利用JAVA反射机制将JSON数据转换成JAVA对象

    net.sf.json.JSONObject为我们提供了toBean方法用来转换为JAVA对象, 功能更为强大,  这里借鉴采用JDK的反射机制, 作为简单的辅助工具使用,   有些数据类型需要进行转 ...

  10. thinkphp 删除多条记录

    删除id为123456的记录 $ids=array(1,2,3,4,5,6);$maps["id"] = array("in",$ids);$this-> ...