Difference between revisions of "Talk:LlList2Json"
Jump to navigation
Jump to search
m (convert tags) |
(bug) |
||
Line 22: | Line 22: | ||
--[[User:Sei Lisa|Sei Lisa]] 17:22, 6 June 2014 (PDT) | --[[User:Sei Lisa|Sei Lisa]] 17:22, 6 June 2014 (PDT) | ||
:Due to {{jira|BUG-6495}} this won't work. Nothing will. JSON is just broken.--[[User:Sei Lisa|Sei Lisa]] ([[User talk:Sei Lisa|talk]]) 07:27, 27 January 2015 (PST) |
Revision as of 07:27, 27 January 2015
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:
string String2Json(string s)
{
return llGetSubString(llList2Json(JSON_OBJECT, [s,""]), 1, -5);
}
Examples:
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"]
--Sei Lisa 17:22, 6 June 2014 (PDT)