json_escape
This function turns a string into a JSON escaped string.
Interface
IO | Parameter | Description | Data Type |
---|---|---|---|
OUT | pDest | Pointer to destination string | UDINT |
IN | pSrc | Pointer to source string | UDINT |
IN | maxLength | Max string length of pDest | UDINT |
OUT | reentry | Pointer to a string pointer. Is populated with a pointer to the next character in pSrc, if end of pSrc is not reached before reaching maxLength. Optional, provide 0 if not desired | UDINT |
OUT | return | New string length of destination | UDINT |
Example
unsigned long reentry, length;
char destination[50];
char source[50];
strcpy(source, "{\"test\": 1}");
length = json_escape(&destination, &source, sizeof(destination)-1, 0);
// destination == "{\\\"test\\\": 1}"
unsigned long reentry, length;
length = json_escape(&tempString, &source, sizeof(destination)-1, &reentry);
strcat(buffer, tempString)
while(reentry != 0){
length = json_escape(&tempString, reentry, sizeof(destination)-1, &reentry);
strcat(buffer, tempString)
}