#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. java7-files读写文件

    package com.du20150311Files; import java.io.BufferedReader; import java.io.BufferedWriter; import ja ...

  2. SqlSever基础 convert 将类型为字符的一列转成Int类型后进行排序

    镇场诗:---大梦谁觉,水月中建博客.百千磨难,才知世事无常.---今持佛语,技术无量愿学.愿尽所学,铸一良心博客.------------------------------------------ ...

  3. Bootstrap_表单

    表单样式 一.基础表单 <form > <div class="form-group"> <label>邮箱:</label> &l ...

  4. hdu4992 Primitive Roots(所有原根)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4992 题意:给出n,输出n的所有原根. 思路:求出n的一个原根x,那么对于所以的i,i<phi( ...

  5. CSS属性前的 -webkit, -moz,-ms,-o

    -moz-对应 Firefox, -webkit-对应 Safari and Chrome-o- for Opera-ms- for Internet Explorer(microsoft) 在CSS ...

  6. SDP学习笔记

    一.SDP规范了回话描述的格式,一般结合会话协议共同工作. 常见的会话传送协议包括:SAP(Session Announcement Protocol 会话公告协议),SIP,RTSP,HTTP,和使 ...

  7. MATLAB模拟布丰投针实验

    MATLAB模拟布丰投针实验 标签(空格分隔): 算法 Buffon's Needle 桌面上有距离为a的若干平行线,将长度为L的针随机丢在桌面上,则这根针与平行线相交的概率是多少?假定L < ...

  8. Using Pre-Form Trigger In Oracle Forms

    Pre-Form trigger in Oracle Forms fires during the form start-up, before forms navigates to the first ...

  9. ,2,liunx命令格式

    一.命令基本格式 ~用户的初始登录位置   /root  这个叫root用户的家目录,每个用户都有自己的家 超级用户的家是根目录,普通用户的家是home下的二级目录   :/home/uer1 pwd ...

  10. firefox 安装flash插件

    第一步下载并解压flash解压出一个文件:libflashplayer.so 和文件夹usr 第二步查找plugins其他程序或许也有这个文件夹所以先查找firefox在查找mozilla看在哪个文件 ...