温度,pn,sn,生产时间和厂家,积分时间,像素长度等变量

This commit is contained in:
wantong
2024-01-31 15:17:21 +08:00
parent 0732984a64
commit c5b2a4e98b
42 changed files with 5275 additions and 8507 deletions

View File

@ -1,7 +1,9 @@
#include <stdio.h>
#include "cJSON_Test.h"
struct paramstruct Parameters;
#include "string.h"
#include "Store_Information.h"
struct paramstruct Parameters; //声明结构体对象
void cjson(uint8_t g_usart_json_string[])
{
@ -10,20 +12,33 @@ void cjson(uint8_t g_usart_json_string[])
cJSON *json = cJSON_Parse(json_string);
if (json != NULL) {
// 获取 JSON 对象中的值
cJSON *name = cJSON_GetObjectItem(json, "name");
cJSON *age = cJSON_GetObjectItem(json, "age");
cJSON *city = cJSON_GetObjectItem(json, "city");
cJSON *waihao = cJSON_GetObjectItem(json, "waihao");
if (name != NULL && age != NULL && city != NULL&& waihao != NULL) {
cJSON *temperature = cJSON_GetObjectItem(json, "temperature");// char * name 是结构体指针通过name->valuestring访问结构体中成员的字符串
cJSON *pn = cJSON_GetObjectItem(json, "pn");
cJSON *sn = cJSON_GetObjectItem(json, "sn");
cJSON *production_date = cJSON_GetObjectItem(json, "production_date");
cJSON *manufacturer = cJSON_GetObjectItem(json, "manufacturer");
cJSON *Device_Pixel_Length = cJSON_GetObjectItem(json, "device_pixel_length");
cJSON *Set_Integration_Time = cJSON_GetObjectItem(json, "set_integration_time");
if (temperature != NULL && pn != NULL && sn != NULL&& production_date != NULL
&& manufacturer != NULL&&Device_Pixel_Length!=NULL&&Set_Integration_Time!=NULL) {
// 打印解析结果
printf("Name: %s\n", name->valuestring);
printf("Age: %d\n", age ->valueint);
printf("City: %s\n", city->valuestring);
// 解析嵌套的对象
printf("Waihao:\n");
parseNestedObject(waihao);
Parameters.age= age->valueint;
Parameters.height=age->valueint;
printf("Temperature: %d\n", temperature->valueint);
printf("Pn:%d\n", pn ->valueint);
printf("Sn:%d\n", sn ->valueint);
printf("Production_date:%d\n", production_date ->valueint);
printf("Manufacturer:%d\n", manufacturer ->valueint);
printf("Device_Pixel_Length:%d\n", Device_Pixel_Length ->valueint);
printf("Set_Integration_Time:%d\n", Set_Integration_Time ->valueint);
Parameters.sn = sn ->valueint;
Parameters.pn = pn->valueint;
Parameters.temperature = temperature->valueint;
Parameters.production_date = production_date->valueint;
Parameters.manufacturer = manufacturer->valueint;
Parameters.Device_Pixel_Length = Device_Pixel_Length->valueint;
Parameters.Set_Integration_Time = Set_Integration_Time->valueint;
}
@ -36,16 +51,7 @@ void cjson(uint8_t g_usart_json_string[])
printf("JSON parsing error.\n");
}
}
void parseNestedObject(cJSON *nestedObject) {
cJSON *waihao1 = cJSON_GetObjectItem(nestedObject, "waihao1");
cJSON *waihao2 = cJSON_GetObjectItem(nestedObject, "waihao2");
if (waihao1 != NULL && waihao2 != NULL) {
// 打印嵌套对象的属性
printf(" waihao1: %s\n", waihao1->valuestring);
printf(" waihao2: %s\n", waihao2->valuestring);
}
}
struct paramstruct *GetParametesptr()
{