1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
|
//解析当前天气
u8 parse_now_weather(void)
{
cJSON *root;
cJSON *pSub;
cJSON *arrayItem;
cJSON *pItem;
cJSON *pSubItem;
cJSON *pChildItem;
char *pr,*utf8str,*gbkstr;
u8 size = 0;
int len;
u8 res;
u8 temperature;
root = mymalloc(SRAMIN,sizeof(cJSON));
pSub = mymalloc(SRAMIN,sizeof(cJSON));
pItem = mymalloc(SRAMIN,sizeof(cJSON));
pSubItem = mymalloc(SRAMIN,sizeof(cJSON));
pChildItem = mymalloc(SRAMIN,sizeof(cJSON));
arrayItem = mymalloc(SRAMIN,sizeof(cJSON));
pr = mymalloc(SRAMIN,1000);
utf8str = mymalloc(SRAMIN,50);
gbkstr = mymalloc(SRAMIN,50);
memset(pr,0,1000);
memset(gbkstr,0,50);
memset(utf8str,0,50);
file = mymalloc(SRAMIN,sizeof(FIL));
res=f_open(file,(const TCHAR*)APP_ASCII_5427,FA_READ);//打开文件
if(res==FR_OK)
{
asc2_5427 = mymalloc(SRAMIN,file->fsize);
if(asc2_5427 != NULL)
{
res = f_read(file,asc2_5427,file->fsize,&br);
}
f_close(file);
}
printf("jieshou->1dayjson = %s\r\n",USART3_RX_BUF);
root = cJSON_Parse((const char*)USART3_RX_BUF);
if(root != NULL)
{
pSub = cJSON_GetObjectItem(root,"results");
if(pSub != NULL)
{
// size = cJSON_GetArraySize(pSub);
arrayItem = cJSON_GetArrayItem(pSub,0);
pr = cJSON_Print(arrayItem); //获取jsom数组
pItem = cJSON_Parse(pr); //对数组,进行升级。
if(pItem != NULL)
{
pSubItem = cJSON_GetObjectItem(pItem,"location");
if(pSubItem != NULL)
{
pChildItem = cJSON_GetObjectItem(pSubItem,"name");
if(pChildItem != NULL)
{
utf8str = pChildItem->valuestring;
SwitchToGbk((const u8*)utf8str,strlen(utf8str),(u8 *)gbkstr,&len); //获取城市名称转换为gbk文件
Show_Str(0,0,lcddev.width,lcddev.height,(u8 *)gbkstr,16,0); //显示城市名称。
}
}
memset(utf8str,0,50); //解决阴华
memset(gbkstr,0,50);
pSubItem = cJSON_GetObjectItem(pItem,"now");
if(pSubItem != NULL)
{
pChildItem = cJSON_GetObjectItem(pSubItem,"text"); //获取天气信息。多云
if(pChildItem != NULL)
{
utf8str = pChildItem->valuestring;
SwitchToGbk((const u8*)utf8str,strlen(utf8str),(u8 *)gbkstr,&len);
Show_Str(220,25,lcddev.width,lcddev.height,(u8 *)gbkstr,16,0); //显示多云
}
memset(utf8str,0,50);
memset(gbkstr,0,50);
pChildItem = cJSON_GetObjectItem(pSubItem,"code"); //获取气象代码
if(pChildItem != NULL)
{
gbkstr = pChildItem->valuestring;
show_weather_icon((u8 *)gbkstr,0); //根据气象代码,更新图片
}
memset(gbkstr,0,50);
pChildItem = cJSON_GetObjectItem(pSubItem,"temperature"); //获取温度信息
if(pChildItem != NULL)
{
gbkstr = pChildItem->valuestring;
temperature = str2int((u8 *)gbkstr);
gui_show_num(140,22,2,RED,54,temperature,0x80);
printf("wendu = %d\r\n",temperature);
}
}
pSubItem = cJSON_GetObjectItem(pItem,"last_updated");
if(pSubItem != NULL)
{
gbkstr =pSubItem->valuestring;
LCD_ShowString(0,92,200,20,12,(u8*)gbkstr);
printf("1day_updata_time = %s\r\n",(u8*)gbkstr);
}
}
cJSON_Delete(pItem);
}
}
cJSON_Delete(root);
myfree(SRAMIN,root);
myfree(SRAMIN,pSub);
myfree(SRAMIN,pItem);
myfree(SRAMIN,pSubItem);
myfree(SRAMIN,pChildItem);
myfree(SRAMIN,arrayItem);
myfree(SRAMIN,pr);
myfree(SRAMIN,utf8str);
myfree(SRAMIN,gbkstr);
myfree(SRAMIN,file);
myfree(SRAMIN,asc2_5427);
return 0;
}
|