From 1b333a0f58d345d37222eb1af821e6ebd457378c Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 12 Sep 2008 15:04:13 +0000 Subject: [PATCH] From: Rob Smart Implement an osParseJSON method useful for handling simple JSON returns from http requests. This will only work in C# at this point. --- .../Common/BuiltIn_Commands_BaseClass.cs | 5 + .../Common/OSSL_BuilIn_Commands.cs | 190 ++++++++++++++++++ .../Common/OSSL_BuilIn_Commands_Interface.cs | 2 + 3 files changed, 197 insertions(+) diff --git a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs index 4fba1fdcac..1b7cc48291 100644 --- a/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs +++ b/OpenSim/Region/ScriptEngine/Common/BuiltIn_Commands_BaseClass.cs @@ -2035,6 +2035,11 @@ namespace OpenSim.Region.ScriptEngine.Common } + public System.Collections.Hashtable osParseJSON(string JSON) + { + return m_LSL_Functions.osParseJSON(JSON); + } + //for testing purposes only public void osSetParcelMediaTime(double time) { diff --git a/OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs index 8b5e879f60..6c7b9daafd 100644 --- a/OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs +++ b/OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs @@ -25,6 +25,7 @@ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ using System; +using System.Collections; using OpenMetaverse; using Nini.Config; using OpenSim.Framework.Console; @@ -582,5 +583,194 @@ namespace OpenSim.Region.ScriptEngine.Common { World.ParcelMediaSetTime((float)time); } + + public Hashtable osParseJSON(string JSON) + { + // see http://www.json.org/ for more details on JSON + + string currentKey=null; + Stack objectStack = new Stack(); // objects in JSON can be nested so we need to keep a track of this + Hashtable jsondata = new Hashtable(); // the hashtable to be returned + + try + { + + // iterate through the serialised stream of tokens and store at the right depth in the hashtable + // the top level hashtable may contain more nested hashtables within it each containing an objects representation + for (int i=0;i