fix error json format when recv sms is empty

This commit is contained in:
fujr 2024-10-28 12:15:01 +08:00
parent be6a045a3b
commit 640196c5b3

View File

@ -744,7 +744,12 @@ int display_sms_in_json(SMS_T **sms,int num)
offset += sprintf(msg_json + offset, "{\"index\":%d,\"sender\":\"%s\",\"timestamp\":%d,\"content\":\"%s\"},", offset += sprintf(msg_json + offset, "{\"index\":%d,\"sender\":\"%s\",\"timestamp\":%d,\"content\":\"%s\"},",
sms[i]->sms_index, sms[i]->sender, sms[i]->timestamp, escaped_text); sms[i]->sms_index, sms[i]->sender, sms[i]->timestamp, escaped_text);
} }
offset--;
//if not empty msg_json,remove the last ','
if (offset > 10)
{
offset--;
}
offset += sprintf(msg_json + offset, "]}"); offset += sprintf(msg_json + offset, "]}");
user_msg("%s\n", msg_json); user_msg("%s\n", msg_json);
return 0; return 0;