Jansson库的使用简介
一、Jansson的安装:
二、jansson相关的API:
https://jansson.readthedocs.io/en/latest/apiref.html#c.json_t
string
object
array
error
number
三、jansson实际如何处理JSON文件:
#include <iostream>
#include "jansson.h"
#include <string.h>
#include <stdio.h>
#include <stdlib.h> using namespace std; int main() {
json_t val;
json_type eval = JSON_REAL;
bool Judge = ;
int type = json_typeof(&val);
Judge = json_is_object(&val);
cout << "json_is_object:" << Judge << endl;
Judge = json_is_array(&val);
cout << "Json_is_array:" << Judge << endl;
cout << "The type of val:" << type << endl; json_t *array, *integer;
array = json_array(); // Create the json array
integer = json_integer(); // Create the json integer
json_array_append(array,integer);
json_decref(integer); /* JSON-STRING */
json_auto_t *value = NULL;
value = json_string("Hello");
json_string_set(value, "World!");
size_t len = json_string_length(value);
cout << "The len of value:" << len << endl; /* JSON-NUMBER */
json_int_t number;
number = ;
printf("number is %" JSON_INTEGER_FORMAT "\n",number);
number = json_integer_value(integer);
printf("value of integer(json_t) is %" JSON_INTEGER_FORMAT "\n",number);
integer = json_real(3.1415926);
double res = json_real_value(integer);
printf("The res is:%f\n",res); /* JSON-ARRAY */
json_t *Matrix = json_array();
json_array_append(Matrix,integer);
size_t Matrix_Size = json_array_size(Matrix);
printf("The size of Matrix:%d\n",Matrix_Size); /* JSON-OBJECT */
json_t *obj = json_object();
size_t obj_size = json_object_size(obj);
printf("The size of obj:%d\n",obj_size);
char *key = "Hello";
int back = json_object_set(obj,key,&val);
printf("The json_object_set correct?%d\n",back); json_t *json_file;
json_error_t error; /* Use the abs-route of the file can read the json file crectlly */
json_file = json_load_file("/home/ubuntu-bitmain/workspace/TestCpp/src/cpuminer-conf.json", , &error);
if(!json_file) printf("No json_file can read!\n");
obj_size = json_object_size(json_file);
printf("The size of json_file:%d\n",obj_size);
json_t *url,*user,*pass;
char *Key_0 = "url";
char *Key_1 = "user";
char *Key_2 = "pass";
url = json_object_get(json_file,Key_0);
user = json_object_get(json_file,Key_1);
pass = json_object_get(json_file,Key_2); Judge = json_is_string(url);
size_t str_length = json_string_length(url);
cout << "The length of url is:" << str_length << endl;
const char *str_res_0 = " ";
str_res_0 = json_string_value(url);
cout << "The length of url is:" << strlen(str_res_0) << endl;
for(int i=;i<strlen(str_res_0);i++){
cout << *(str_res_0+i);
}
cout << endl;
cout << "The url is string" << Judge << endl; return ;
}
四、从网上获取JSON文件并解析:
完~
Jansson库的使用简介的更多相关文章
- 【液晶模块系列基础视频】4.2.X-GUI图形界面库-画矩形函数简介
[液晶模块系列基础视频]4.2.X-GUI图形界面库-画矩形函数简介 ============================== 技术论坛:http://www.eeschool.org 博客地址: ...
- 【c++】标准模板库STL入门简介与常见用法
一.STL简介 1.什么是STL STL(Standard Template Library)标准模板库,主要由容器.迭代器.算法.函数对象.内存分配器和适配器六大部分组成.STL已是标准C++的一部 ...
- GNU Readline 库及编程简介
用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以用来命令补全 ↑ 或 ↓ 键可以用来快速输入历史命令 还有一些交互式行编辑快捷键: C-A / C-E 将光标移到行首/行尾 C ...
- 安装jansson库【JSON库C语言版】
本次操作在Ubuntu 14.04下进行,其他的系统大同小异,安装软件时请根据系统版本进行调整. 1.下载jansson源码: git clone https://github.com/akheron ...
- JSP标准标签库(JSTL)--JSTL简介与安装
对于MVC设计模式来讲,我们一直强调,在一个JSP钟scriptlet代码越少越好,但是只靠以前的概念很难实现,因为标签的开发特别麻烦,所以为了简化标签,也为了让标签更具备一些通用性,所以一般在开发中 ...
- 开源高性能网络库Libevent的简介
Libevent是什么? Libevent 是一个用C语言编写的.轻量级的开源高性能网络库. 官网:http://libevent.org/ 优点: (1)事件驱动,高性能 (2)轻量级,专注于网络 ...
- GNU Readline 库及编程简介【转】
转自:https://www.cnblogs.com/hazir/p/instruction_to_readline.html 用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以 ...
- iOS开发——高级篇——换肤、静态库
一.换肤 1.思路1> 解决方案1,使用颜色作为图片素材的命名关键字 问题1:要保证每套图片的文件名 颜色+ 名称.png的格式比较麻烦 问题2:如果要将某一个图片应用到其他皮肤不方便2> ...
- 自己动手写一个iOS 网络请求库的三部曲[转]
代码示例:https://github.com/johnlui/Swift-On-iOS/blob/master/BuildYourHTTPRequestLibrary 开源项目:Pitaya,适合大 ...
随机推荐
- Ironic 裸金属管理服务的底层技术支撑
目录 文章目录 目录 底层技术支撑 DHCP NBP TFTP IPMI PXE & iPXE Cloud Init Linux 操作系统启动引导过程 底层技术支撑 PXE:预启动执行环境,支 ...
- AngularJS unit test report / coverage report
参考来源: http://www.cnblogs.com/vipyoumay/p/5331787.html 这篇是学习基于Angularjs的nodejs平台的单元测试报告和覆盖率报告.用到的都是现有 ...
- SQL学习(二)SQL基础的增删改查
在测试时使用数据库时,用的比较多的就是增删改查SQL了. 一.增加(insert into ...values) 用于向表中插入新记录 1.不指定列(表示:依次插入所有列的值) insert into ...
- Python学习小技巧之列表项的排序
Python学习小技巧之列表项的排序 本文介绍的是关于Python列表项排序的相关内容,分享出来供大家参考学习,下面来看看详细的介绍: 典型代码1: data_list = [6, 9, 1, ...
- Oracle:常用操作(定时作业,逻辑导入,数据泵导入)
1.逻辑导入: /*第1步:创建临时表空间 **/ create temporary tablespace user_temp1 tempfile 'D:\app\Administrator\orad ...
- PYTHON TDD学习(一)-->Python 3.4版本环境安装Django及其启动
1.安装Python3.4版本,原因:3.4及其以后版本默认自带pip工具,非常好用 2.django 安装命令(c:\Python34\Scripts):pip install django 3.s ...
- Lua for Mac环境搭建
1⃣️在Mac上安装Lua的运行环境再简单不过了,如果你的Mac Terminal上安装了Homebrew的话,只需要键入`brew install lua`即可. longsl-mac:~ long ...
- wms、wmts和wfs的区别
Web地图服务(WMS)利用具有地理空间位置信息的数据制作地图.其中将地图定义为地理数据可视的表现.这个规范定义了三个操作:GetCapabilities返回服务级元数据,它是对服务信息内容和要求参数 ...
- [转载]Jupyter Notebook 的快捷键
原文:http://blog.csdn.net/lawme/article/details/51034543 Jupyter Notebook 的快捷键 Jupyter Notebook 有两种键盘输 ...
- Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper)
Leetcode之广度优先搜索(BFS)专题-529. 扫雷游戏(Minesweeper) BFS入门详解:Leetcode之广度优先搜索(BFS)专题-429. N叉树的层序遍历(N-ary Tre ...