Hi all! Maybe someone can help with this problem I currently have. Thanks!
I am trying to send a JSON string via socket_send_string URScript command. The URScript code is generated in an URCaps plugin. A simple example of the line generating the code in the URCaps:
This produces a syntax error when trying to execute the URScript. The reason for this seems to be the inner quotation marks in the JSON string I am trying to send, as just sending \"{ProcessState: 4}\" works fine. Unfortunately I need these for proper JSON parsing. Is there a way to properly send JSON with this command (or a different URScript command)?
We send JSON strings via XMLRPC back to the server. What we had to do though was invert the quote structure and then we swap it on the server side before processing the now valid JSON. Basically you can use single quotes inside a string but in UR a string must be wrapped in double quotes so a json string would look something like this:
"{'key':numberValue, 'key:'stringValue'}"
Then on the server we changed the ' to " using a regex command then parsed the JSON and returned the result back to the calling function. Our XMLRPC server is running NodeJS so handling JSON is rather straightforward. We even have a function for taking in a series of keys and values as a number of parameters and returning a valid stringified JSON string that UR would accept, then we could keep adding values to the same string if we wanted.
So in your example we would have sent writer.appendRaw("socket_send_string(\"{'ProcessState': 4}\", \"my_socket\")");