Fix handling of string values in JsonSetValueJson(). There are

some oddities with empty strings: the Json serializer treats them
as default values and does not return them in serialized hashes.
0.7.4-extended
Mic Bowman 2013-02-11 19:55:10 -08:00 committed by Justin Clark-Casey (justincc)
parent 7d68559e15
commit 914ebd7476
1 changed files with 31 additions and 1 deletions

View File

@ -180,7 +180,37 @@ namespace OpenSim.Region.OptionalModules.Scripting.JsonStore
// -----------------------------------------------------------------
public bool SetValue(string expr, string value, bool useJson)
{
OSD ovalue = useJson ? OSDParser.DeserializeJson(value) : new OSDString(value);
OSD ovalue;
// One note of caution... if you use an empty string in the
// structure it will be assumed to be a default value and will
// not be seialized in the json
if (useJson)
{
// There doesn't appear to be a good way to determine if the
// value is valid Json other than to let the parser crash
try
{
ovalue = OSDParser.DeserializeJson(value);
}
catch (Exception e)
{
if (value.StartsWith("'") && value.EndsWith("'"))
{
ovalue = new OSDString(value.Substring(1,value.Length - 2));
}
else
{
return false;
}
}
}
else
{
ovalue = new OSDString(value);
}
return SetValueFromExpression(expr,ovalue);
}