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,适合大 ...
随机推荐
- kubernetes学习:CKA考试认证
考点 CKA认证针对考核成为当业界的Kubernetes管理员所需的技能. CKA认证考试包括这些一般领域及其在考试中的权重: 应用程序生命周期管理 - 8% 安装.配置和验证 - 12% 核心概 ...
- 程序员查问题还是要找stackoverflow
今天定位了一个问题,其实也不是多复杂. 现场的数据是postgres dump出来的,想拿到本地服务器restore后定位问题. 本地restore后报错,报sequence as data_type ...
- Linux进程间通信(IPC)之信号量
[Linux]进程间通信(IPC)之信号量详解与测试用例 2017年03月22日 17:28:50 阅读数:2255 学习环境centos6.5 Linux内核2.6 进程间通信概述 1. 进程通信机 ...
- robotframework-requests--中文注解版
最近工作原因在研究RobotFramework对REST测试的方案,找到几个相关类库.但使用requests感觉更方便,研究了一下requests类库的源码,并将注释换成中文为方便使用.关于Reque ...
- 【MM系列】SAP技巧之更改布局
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[MM系列]SAP技巧之更改布局 前言部分 ...
- UOJ#548.数学
#include<iostream> #include<algorithm> #include<cmath> #include<cstdio> #inc ...
- Ubuntu下借助URLOS实现快速安装DzzOffice企业办公套件
如今,越来越多的个人.团队甚至企业都在使用GSuite或者Office365等网络办公套件,为什么人们越来越喜爱使用网络办公套件?一方面是考虑数字资产的安全性以及管理效率,另一方面则是日益增大的协同办 ...
- AS将一个项目导入到另一个项目中
需求:有项目A,B.需要将B集成到A中,作为A的一个模块. 方法: 1.将B工程的app下面的build.gradle文字中 apply plugin: 'com.android.applicati ...
- "alert(1) to win" writeup
地址:http://escape.alf.nu/ level 0: 注意补全,");alert(1)// level 1: 通过添加反斜线使用来转义的反斜线变为字符,\");ale ...
- 小记---------spark优化之更优分配资源
spark优化:在一定范围之内,增加资源与性能的提升是成正比的. 因此, 一个cpu core 执行一个task线程. task数: 若有 cpu core 2个.num-execu ...