首先, 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串的更多相关文章

  1. 怎么解析json串在.net中

    以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JObject jo = JObject.Parse(json); ...

  2. 在.net中怎么解析json串 [Error reading JObject from JsonReader. Current JsonReader item is not an obj]

    编辑时间:2017-05-10,增加一种转化list的方法 一.以前知道一种解析json串的方法,觉得有点麻烦.就从别的地方搜到了另一种 string json = vlt.getlist(); JO ...

  3. SpringMVC Jackson 库解析 json 串属性名大小写自动转换问题

    问题描述 在项目开发中,当实体类和表中定义的某个字段为 RMBPrice,首字母是大写的,sql 查询出来的列名也是大写的 RMBPrice,但是使用 jquery 的 ajax 返回请求响应时却出错 ...

  4. java解析json串获取key和value

    网上例子巨多,纯属个人笔记: JSONObject maleArray = maleObject.getJSONObject("extension"); Iterator<S ...

  5. JavaScript中使用eval()方法解析json串

    最近在js用到了eval()方法,在这里做个笔记 当时是这么用的:data = eval("("+data+")"); data为后台向前台传送的一个json串 ...

  6. ANDROID_MARS学习笔记_S02_013_Gson解析json串

    1.MainActivity.java package com.json; import java.io.IOException; import java.io.StringReader; impor ...

  7. 使用jackson解析json串得到树模型,然后遍历树模型获得需要的数据

    Problem:从网址 http://quotes.money.163.com/hs/service/marketradar_ajax.php?host=http%3A%2F%2Fquotes.mon ...

  8. 解析json串,利用正则表达式,split

    public class SplitJson { public static void main(String[] args) {        // TODO Auto-generated meth ...

  9. iOS 解析json串

    NSString *json = @"[{\"name\":\"a1\",\"items\":[{\"x1\" ...

随机推荐

  1. GPU安装小结

    今天一起安装了4块1080的卡.也算有一些坑吧,记录一下. 1)1080显卡,驱动型号,tensorflow,cuda, cudnn 版本一定要一致.我的清单如下: ################# ...

  2. 【紫书】Ordering Tasks UVA - 10305 拓扑排序:dfs到底再输出。

    题意:给你一些任务1~n,给你m个数对(u,v)代表做完u才能做v 让你给出一个做完这些任务的合理顺序. 题解:拓扑排序版题 dfs到底再压入栈. #define _CRT_SECURE_NO_WAR ...

  3. centos7安装zabbix客户端并监控

    zabbxi-agent安装及配置 1.安装zabbxi-agent yum install zabbix-agent -y 2.配置zabbxi-agent grep -n '^'[a-Z] /et ...

  4. 如何实现浏览器向服务器伪造refer?

    Request URL:https://www.getwnmp.org/ Request Method:GET Status Code:304 Remote Address:45.55.134.251 ...

  5. PHP之获取终端用户IP

    // function get_real_ip() { $ip=false; $clientip = "clientip"; $xrealip = "xrealip&qu ...

  6. python 查找函数的用法

    python的导入模块:python解释器先检查当前目录下的导入的模块,如果没有找到再检查sys模块中path中的变量(import sys,sys.path),如果没有找到,就会发生错误.可以使用脚 ...

  7. LeetCode 812 Largest Triangle Area 解题报告

    题目要求 You have a list of points in the plane. Return the area of the largest triangle that can be for ...

  8. Gson使用技巧

    1. CharMatcher String serviceUrl = CharMatcher.is('/').trimTrailingFrom(ConfigHelper.metaServiceUrl( ...

  9. scss是什么?在vue.cli中的安装使用步骤是?有哪几大特性?

    css的预编译: 使用步骤: 第一步:用npm下三个loader(sass-loader.css-loader.node-sass): 第二步:在build目录找到webpack.base.confi ...

  10. oracle闪回的使用

    1.闪回查询(原理:依赖于UNDO表空间)查询当前SCN号select current_scn from v$database;误删数据以后select * from table_name as of ...