C++ 解析json串
首先, C++ 解析json串,需要用到第三方库(json_vc71_libmtd.lib)。然后,VS2010,创建项目json_read,配置项目属性。最后,拷贝下面的代码就可以看到效果了。
#include "stdafx.h"
#include "../json/include/json.h" int _tmain(int argc, _TCHAR* argv[])
{
const char * str = "{\"machineCode\":\"20:20:20:20:20:20:57:4c:31:30:59:31:4d:56\",\"makeTime\":1534485879,\"sysCapacity\":{\"rptMaxNum\":2},\"trialTime\":30}";
printf("json 串:%s\n", str); Json::Reader reader;
Json::Value root;
if(reader.parse(str,root))
{
std::string machineCode = root["machineCode"].asString();
long long makeTime = root["makeTime"].asUInt();
int rptMaxNum = root["rptMaxNum"].asInt();
int trialTime = root["trialTime"].asInt(); printf("解析json串之后的值:\n");
printf("machineCode = %s\n",machineCode.c_str());
printf("makeTime = %ld\n",makeTime);
printf("rptMaxNum = %d\n",rptMaxNum);
printf("trialTIme = %d\n",trialTime); Json::Value & sysCapacity = root["sysCapacity"];
int rpt = sysCapacity["rptMaxNum"].asInt();
printf("rptMaxNum = %d\n",rpt);
}
system("pause");
return ;
}
附I:json在线格式化工具
附II:项目用到第三方库资源,有库,有头文件的时候,建议分类创建一个文件夹,便于阅读和重用。

附录III:运行结果

C++ 解析json串的更多相关文章
- 怎么解析json串在.net中
以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JObject jo = JObject.Parse(json); ...
- 在.net中怎么解析json串 [Error reading JObject from JsonReader. Current JsonReader item is not an obj]
编辑时间:2017-05-10,增加一种转化list的方法 一.以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JO ...
- SpringMVC Jackson 库解析 json 串属性名大小写自动转换问题
问题描述 在项目开发中,当实体类和表中定义的某个字段为 RMBPrice,首字母是大写的,sql 查询出来的列名也是大写的 RMBPrice,但是使用 jquery 的 ajax 返回请求响应时却出错 ...
- java解析json串获取key和value
网上例子巨多,纯属个人笔记: JSONObject maleArray = maleObject.getJSONObject("extension"); Iterator<S ...
- JavaScript中使用eval()方法解析json串
最近在js用到了eval()方法,在这里做个笔记 当时是这么用的:data = eval("("+data+")"); data为后台向前台传送的一个json串 ...
- ANDROID_MARS学习笔记_S02_013_Gson解析json串
1.MainActivity.java package com.json; import java.io.IOException; import java.io.StringReader; impor ...
- 使用jackson解析json串得到树模型,然后遍历树模型获得需要的数据
Problem:从网址 http://quotes.money.163.com/hs/service/marketradar_ajax.php?host=http%3A%2F%2Fquotes.mon ...
- 解析json串,利用正则表达式,split
public class SplitJson { public static void main(String[] args) { // TODO Auto-generated meth ...
- iOS 解析json串
NSString *json = @"[{\"name\":\"a1\",\"items\":[{\"x1\" ...
随机推荐
- -bash: fork: Cannot allocate memory
今天遇到服务器无法SSH,VNC操作命令提示fork:cannot allocate memory free查看内存还有(注意,命令可能要多敲几次才会出来) 查看最大进程数 sysctl kernel ...
- PE/ELF文件里面存的是什么呢?
malloc分配的空间是连续的吗?PE/ELF文件里面存的是什么呢?
- [daily][gnucash] 复式记账
管理, 是成就人生的第一步. 管钱,是第一步中的第一小步. 选了又选,终于选了一个软件,gnucash, 但是, 他有点专业, 用之前需要搞懂一下会计概念. 即: 复式记账 gnucash手册的这一章 ...
- Copycat - CopycatServer
Server被拉起有两种方式, Address address = new Address("123.456.789.0", 5000); CopycatServer.Builde ...
- textfield内边距
使用QMUITextField self.inputTf.textInset = UIEdgeInsetsMake(0, -6, 0, 10);
- 搭建Kubernetes服务集群遇到的问题
kube-proxy问题: Apr 12 09:42:49 compute1 kube-proxy[12965]: E0412 09:42:49.602342 12965 reflector.go:2 ...
- 启动虚拟机提示"Units specified don’t exist SHSUCDX can’t install"
新建虚拟机快速分区后启动报"Units specified don’t exist SHSUCDX can’t install",试过网上说的 修改BIOS设置方法不起作用 修改虚 ...
- Jenkins 忘记admin用户名以及密码
1.进入 如果安装的war包,路劲如下: C:\Users\LENOVO\.jenkins\ 2. 1)方式一: 打开config.xml ->将useSecurity设置为false 2)方 ...
- svn 修改文件的可执行权限
设置svn可执行权限,svn:executable 1)svn propset svn:executable on 文件名/文件夹名 2)svn propset svn:executable on t ...
- 【PyQt5-Qt Designer】对话框系列
标准输入对话框(QInputDialog)系列: 主要模块 from PyQt5.QtWidgets import QInputDialog 效果如下: 完整代码: from PyQt5.QtWidg ...