找回密码
 立即注册

使用微信账号登录

只需一步,快速开始

查看: 9|回复: 0

[Nordic] NCS怎么调用CJSPN库?

[复制链接]

暂无签到数据

发表于 昨天 20:20 | 显示全部楼层 |阅读模式
这个文章讲一下在NCS上面如何使用JSON库,我使用的是Hello_world例程


1、 宏的配置
CONFIG_LOG=y
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_CJSON_LIB=y
CONFIG_NEWLIB_LIBC=y
CONFIG_NEWLIB_LIBC_FLOAT_PRINTF=y



2、 main文件添加头文件

#include <stdio.h>
#include "cJSON.h"



3、调用库就行了

int main(void)


{


double Heart_Rate = 5.5;


uint8_t buf[15] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x10,0x0A,0X0B,0X0C,0X0D,0X0E};


cJSON *root =cJSON_CreateObject();


cJSON *arr = cJSON_AddArrayToObject(root,"test");


cJSON_AddNumberToObject(root,"Heart rate",Heart_Rate);


for ( uint8_t i = 0; i < sizeof(buf); ++i)


{


cJSON_AddItemToArray(arr,cJSON_CreateNumber(buf));


}
char *str=cJSON_Print(root);


printk("%s",cJSON_Print(root));
printf("Hello World! %s\n", CONFIG_BOARD_TARGET);
return 0;


}
4、测试




本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册  

×
楼主热帖
积分商城 - 让您的金币更有价值!||官方Q群 - 让您的沟通更加及时!
您需要登录后才可以回帖 登录 | 立即注册  

本版积分规则

小黑屋|手机版|我爱蓝牙网 - 52Bluetooth

GMT+8, 2025-7-21 17:31 , Processed in 0.147946 second(s), 14 queries , Gzip On, MemCached On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表