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,适合大 ...
随机推荐
- Telnet设置
修改hostname:修改/etc/hosts文件vi /etc/hosts# Do not remove the following line, or various programs# that ...
- nohup sh start.sh >/dev/null 2>&1 &
nohup sh start.sh >/dev/null 2>&1 & 背景说明 start.sh 脚本里,写了Java应用程序启动的相关命令,并且在 log4j.prop ...
- dokcer部署code-server web版vscode
#dokcer部署code-server web版vscode codercom/code-server:latest不支持插件在线安装 codercom/code-server:v2目前为最新版1. ...
- 【JVM学习笔记】类加载器
概述 类加载器用来把类加载到Java虚拟机中.从JDK1.2版本开始,类的加载过程采用父委托机制,这种机制能更好地保证Java平台的安全.在此委托机制中,除了Java虚拟机自带的根类加载器以外,其余的 ...
- golang 数据类型之间的转换
一.基本数据类型之间的转换 1.string到int int,err:=strconv.Atoi(string) 2.string到int64 int64, err := strconv.ParseI ...
- python操作轻量级数据库
1.导入Python SQLITE数据库模块 Python2.5之后,内置了SQLite3,成为了内置模块,这给我们省了安装的功夫,只需导入即可~ import sqlite3 2. 创建/打开数据库 ...
- Linux后台运行python程序并输出到日志文件
后台运行python程序并标准输出到文件 现在有test.py程序要后台部署, 里面有输出内容 使用命令: nohup python -u test.py > test.log 2>&am ...
- 手写k-means算法
作为聚类的代表算法,k-means本属于NP难问题,通过迭代优化的方式,可以求解出近似解. 伪代码如下: 1,算法部分 距离采用欧氏距离.参数默认值随意选的. import numpy as np d ...
- AS将一个项目导入到另一个项目中
需求:有项目A,B.需要将B集成到A中,作为A的一个模块. 方法: 1.将B工程的app下面的build.gradle文字中 apply plugin: 'com.android.applicati ...
- 图解DMZ
图解DMZ 1. 概念介绍 DMZ是英文“demilitarized zone”的缩写,中文译为“隔离区”.“非军事区”.它是为了解决安装防火墙后外部网络不能访问内部网络服务器的问题,而设立的一个非安 ...