From 640196c5b3c5df1f7e4cb50ba5f494586ddbf5b5 Mon Sep 17 00:00:00 2001 From: fujr Date: Mon, 28 Oct 2024 12:15:01 +0800 Subject: [PATCH] fix error json format when recv sms is empty --- application/tom_modem/src/utils.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/application/tom_modem/src/utils.c b/application/tom_modem/src/utils.c index 41bf5eb..d33daa7 100644 --- a/application/tom_modem/src/utils.c +++ b/application/tom_modem/src/utils.c @@ -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\"},", 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, "]}"); user_msg("%s\n", msg_json); return 0;