一、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库的使用简介的更多相关文章

  1. 【液晶模块系列基础视频】4.2.X-GUI图形界面库-画矩形函数简介

    [液晶模块系列基础视频]4.2.X-GUI图形界面库-画矩形函数简介 ============================== 技术论坛:http://www.eeschool.org 博客地址: ...

  2. 【c++】标准模板库STL入门简介与常见用法

    一.STL简介 1.什么是STL STL(Standard Template Library)标准模板库,主要由容器.迭代器.算法.函数对象.内存分配器和适配器六大部分组成.STL已是标准C++的一部 ...

  3. GNU Readline 库及编程简介

    用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以用来命令补全 ↑ 或 ↓ 键可以用来快速输入历史命令 还有一些交互式行编辑快捷键: C-A / C-E 将光标移到行首/行尾 C ...

  4. 安装jansson库【JSON库C语言版】

    本次操作在Ubuntu 14.04下进行,其他的系统大同小异,安装软件时请根据系统版本进行调整. 1.下载jansson源码: git clone https://github.com/akheron ...

  5. JSP标准标签库(JSTL)--JSTL简介与安装

    对于MVC设计模式来讲,我们一直强调,在一个JSP钟scriptlet代码越少越好,但是只靠以前的概念很难实现,因为标签的开发特别麻烦,所以为了简化标签,也为了让标签更具备一些通用性,所以一般在开发中 ...

  6. 开源高性能网络库Libevent的简介

    Libevent是什么? Libevent 是一个用C语言编写的.轻量级的开源高性能网络库. 官网:http://libevent.org/ 优点: (1)事件驱动,高性能 (2)轻量级,专注于网络 ...

  7. GNU Readline 库及编程简介【转】

    转自:https://www.cnblogs.com/hazir/p/instruction_to_readline.html 用过 Bash 命令行的一定知道,Bash 有几个特性: TAB 键可以 ...

  8. iOS开发——高级篇——换肤、静态库

    一.换肤 1.思路1> 解决方案1,使用颜色作为图片素材的命名关键字 问题1:要保证每套图片的文件名 颜色+ 名称.png的格式比较麻烦 问题2:如果要将某一个图片应用到其他皮肤不方便2> ...

  9. 自己动手写一个iOS 网络请求库的三部曲[转]

    代码示例:https://github.com/johnlui/Swift-On-iOS/blob/master/BuildYourHTTPRequestLibrary 开源项目:Pitaya,适合大 ...

随机推荐

  1. 关于ansbile

    YAML语法规则 规则一:缩进(一个缩进两空格,注意一定不用tab) 规则二:冒号(每个冒号后一定要有空格) 规则三:短横线 - (短横线后面要空格) 编写案例 ansible-playbook -- ...

  2. (转载)IDEA中对Git的常规操作(合并,提交,新建分支,更新)

    工作中多人使用版本控制软件协作开发,常见的应用场景归纳如下: 假设小组中有两个人,组长小张,组员小袁 场景一:小张创建项目并提交到远程Git仓库 场景二:小袁从远程Git仓库上获取项目源码 场景三:小 ...

  3. 2019.11.29 SAP SMTP郵件服務器配置 發送端 QQ郵箱

    今天群裏的小夥伴問了如何配置郵件的問題,隨自己在sap裏面配置了一個 1.    RZ10配置參數 a)       参数配置前,先导入激活版本 执行完毕后返回 b)      输入参数文件DEFAU ...

  4. linux常用命令(14)which命令

    我们经常在linux要查找某个文件,但不知道放在哪里了,可以使用下面的一些命令来搜索:    which  查看可执行文件的位置.   whereis 查看文件的位置.    locate   配合数 ...

  5. Apache POI读取Excel

    1.pom.xml配置文件 <!-- 配置Apache POI --> <dependency> <groupId>org.apache.poi</group ...

  6. Tensorflow 从文件中载入训练数据

    本节包含: 用纯文本文件准备训练数据 加载文件中的训练数据 一.用纯文本文件准备训练数据 1.数据的数字化 比如,“是” —— “1”,“否” —— “0” “优”,“中”,“差” —— 1 2 3  ...

  7. Centos7 安装多版本php 并添加swoole拓展

    服务器默认安装了php7 直接使用lnmp工具包安装php5.6 使用之前的lnmp安装包,切换到root sudo su - 运行 选择5.6 安装完成 没有安装swoole拓展 由官方https: ...

  8. [c++] 用宏定义一个函数

    要点:变量都用括号括起来,防止出错,结尾不需要;.在实际编程中,不推荐把复杂的函数使用宏,不容易调试.多行用\ 要写好C语言,漂亮的宏定义是非常重要的.宏定义可以帮助我们防止出错,提高代码的可移植性和 ...

  9. 纯前端表格控件SpreadJS以专注业务、提升效率赢得用户与市场

    提起华为2012实验室,你可能有点陌生. 但你一定还对前段时间华为的那封<海思总裁致员工的一封信>记忆犹新,就在那篇饱含深情的信中,我们知道了华为为确保公司大部分产品的战略安全和连续供应, ...

  10. 友善的树形DP

    一棵树,如果有序点对(x,y)之间路径的长度取模于3==0,那么ans0便加上这个长度: 如果取模于3==1,那么ans1便加上这个长度: 如果取模于3==2,那么ans2便加上这个长度: 让你求an ...