#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. c# monitor锁

    当多个线程在并发的时候,难免会碰到相互冲突的事情,比如最经典的ATM机的问题,并发不可怕,可怕的是我们没有能力控制. 线程以我的理解可以分为三种 ① 锁. ② 互斥. ③ 信号. 好,这一篇主要整理“ ...

  2. Mix and Build(简单DP)

    Mix and Build Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3936 Accepted: 1203 Case Ti ...

  3. python3数据类型

    python基本数据类型 Python3 中有六个标准的数据类型: Number(数字) String(字符串) List(列表) Tuple(元组) Sets(集合) Dictionary(字典) ...

  4. codevs4817 江哥的dp题d

    4817 江哥的dp题d  时间限制: 1 s  空间限制: 256000 KB  题目等级 : 黄金 Gold [题目描述] Description 已知1-N的排列P的LIS(最长上升子序列)不超 ...

  5. bootstrap ace MVC

    <<html lang="en"><head> <meta charset="utf-8" /> <title& ...

  6. 解决This function or variable may be unsafe

    工程名字右键属性-->C/C++-->预处理器-->预处理器定义-->加入:_CRT_SECURE_NO_WARNINGS

  7. JQuery增删改查

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. 【leetcode❤python】232. Implement Queue using Stacks

    #-*- coding: UTF-8 -*-#双栈法class Queue(object):    def __init__(self):        """      ...

  9. BZOJ 3752 世界树

    题目链接:http://www.lydsy.com:808/JudgeOnline/problem.php?id=3572 题意:给出一棵树.若干询问.每个询问给出m个点,输出每个点管辖的点的个数.x ...

  10. UVA 1291 十四 Dance Dance Revolution

    Dance Dance Revolution Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Su ...