My application receives a JSon message via UDP from coordinates of an object as follows:
{
"FRAME1": {
"X": "-0.885498",
"Y": "-0.205078",
"Z": "0.628174"
},
"FRAME2": {
"X": "1.70898",
"Y": "-5.67627",
"Z": "0.305176"
},
"ID": "DEVICE9",
"TS": "7.9900"
}
I need to read the coordinates from FRAME1 and FRAME2 (X,Y,Z values of each frame). The Json message is stored in char[] msg. I use these the following lines of code two get the coordinates of FRAME1:
char Xc[32], Yc[32], Zc[32];
sscanf (msg,
"{\"X\":\"%s\",\"Y\":\"%s\",\"Z\":\"%s\"}",
Xc, Yc, Zc);
I display the stored value with printf as:
printf("X coordinate is: %s\n" , Xc);
The output, however is strange:
X coordinate is: |-
What is wrong in the format provided for sscanf()?
sscanf? Maybe you should!sscanfformat string contain some whitespace between the colons and the double quotes?