Difference between revisions of "Talk:LlJsonSetValue"

From Second Life Wiki
Jump to navigation Jump to search
Line 25: Line 25:
---------
---------
Sadly, even this isn't a complete solution. With a URL like "http://www.google.com/", you'll get a "leaning-toothpicks" style value, but a call to llJsonSetValue() still won't pack it in correctly.  -- [[User:Lavanya Hartnell|Lavanya Hartnell]] 7:45, 11 August 2014 (PDT)
Sadly, even this isn't a complete solution. With a URL like "http://www.google.com/", you'll get a "leaning-toothpicks" style value, but a call to llJsonSetValue() still won't pack it in correctly.  -- [[User:Lavanya Hartnell|Lavanya Hartnell]] 7:45, 11 August 2014 (PDT)
:Works for me. Can you give an example? Mine was <code>llJsonSetValue("[]",[0],String2Json("http://www.google.com/"))</code> and it returned the correct JSON -- [[User:Sei Lisa|Sei Lisa]] 10:39, 11 September 2014 (PDT)

Revision as of 09:39, 11 September 2014

Safe strings

Passing strings verbatim to llJsonSetValue or llList2Json is not safe. One way to escape strings properly to make them safe for use with both is to use this function: <lsl> string String2Json(string s) {

   return llGetSubString(llList2Json(JSON_OBJECT, [s,""]), 1, -5);

} </lsl> Examples: <lsl> llOwnerSay(String2Json(llUnescapeURL("%09"))); // outputs: Object: "\t" llOwnerSay(String2Json("\n")); // outputs: Object: "\n" llOwnerSay(String2Json("this \"string\" is not safe")); // outputs: Object: "this \"string\" is not safe" llOwnerSay(String2Json("\"ab\"")); // outputs: Object: "\"ab\""

// Examples of use with the corresponding functions: llOwnerSay(llJsonSetValue("[]", [0], String2Json("this \"string\" is not safe"))); llOwnerSay(llList2Json(JSON_ARRAY, [String2Json("this \"string\" is not safe")])); // both output: Object: ["this \"string\" is not safe"] </lsl>

--Sei Lisa 17:19, 6 June 2014 (PDT)


Sadly, even this isn't a complete solution. With a URL like "http://www.google.com/", you'll get a "leaning-toothpicks" style value, but a call to llJsonSetValue() still won't pack it in correctly. -- Lavanya Hartnell 7:45, 11 August 2014 (PDT)

Works for me. Can you give an example? Mine was llJsonSetValue("[]",[0],String2Json("http://www.google.com/")) and it returned the correct JSON -- Sei Lisa 10:39, 11 September 2014 (PDT)