From 65157ffb04b5f97ff100ba5b17eee1775820325d Mon Sep 17 00:00:00 2001 From: Bridget Date: Mon, 13 Apr 2020 14:07:34 +0200 Subject: [PATCH] Properly serialize into JSON --- endpoint.lsl | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/endpoint.lsl b/endpoint.lsl index cca41b7..42bd84f 100644 --- a/endpoint.lsl +++ b/endpoint.lsl @@ -19,8 +19,7 @@ default } else if(id == request_id && num == 1) { - // TODO Properly escape and serialize to JSON - llHTTPResponse(id, 200, "{\"result\": \"" + msg + "\"}"); + llHTTPResponse(id, 200, llList2Json(JSON_OBJECT, ["result", msg])); request_id = ""; } } @@ -46,18 +45,22 @@ default { if(llJsonGetValue(body, ["command"]) == "init") { - llHTTPResponse(id, 200, "{\"uuid\": \"" + string(llGetKey()) + "\"}"); + llHTTPResponse(id, 200, llList2Json(JSON_OBJECT, + ["uuid", llGetKey()])); connected = 1; } else if(llJsonGetValue(body, ["command"]) == "disconnect") { - llHTTPResponse(id, 200, "{\"result\": \"disconnected\"}"); + llHTTPResponse(id, 200, llList2Json(JSON_OBJECT, + ["result", "disconnected"])); connected = 0; } else if(llJsonGetValue(body, ["command"]) == "get_commands") { - llHTTPResponse(id, 200, "{\"available_commands\": " + \ - llList2Json(JSON_OBJECT, commands) + "}"); + llHTTPResponse(id, 200, llList2Json(JSON_OBJECT, + ["available_commands", + llList2Json(JSON_OBJECT, commands) + ])); } else { @@ -68,7 +71,8 @@ default } else { - llHTTPResponse(id, 401, "{\"error\": \"Invalid secret key\"}"); + llHTTPResponse(id, 401, llList2Json(JSON_OBJECT, + ["error", "Invalid secret key"])); } } }