#include <stdio.h>
#include <stdlib.h>
char t_json[300];
int main()
{
int DeviceID = 10;
int BatteryNum = 10;
float Temperatrue = 10.1;
int Humid = 10;
float ThisHourRainfall = 10.1;
char json[]="{\"services\":[{\"service_id\":\"Device\",\"properties\":{\"DeviceID\":%d}},\
{\"service_id\":\"Battery\",\"properties\":{\"BatteryNum\":%d},\
{\"service_id\":\"wendu\",\"properties\":{\"Temperature\":%.1f},\
{\"service_id\":\"shidu\",\"properties\":{\"Humid\":%d},\
{\"service_id\":\"Rainfall\",\"properties\":{\"ThisHourRainfall\":%.1f}\
]}";
sprintf(t_json, json, DeviceID, BatteryNum,Temperatrue,Humid,ThisHourRainfall);
printf("%s",t_json);
return 0;
}
|