From 1b333a0f58d345d37222eb1af821e6ebd457378c Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Fri, 12 Sep 2008 15:04:13 +0000 Subject: 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. --- .../ScriptEngine/Common/OSSL_BuilIn_Commands.cs | 190 +++++++++++++++++++++ 1 file changed, 190 insertions(+) (limited to 'OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs') diff --git a/OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs b/OpenSim/Region/ScriptEngine/Common/OSSL_BuilIn_Commands.cs index 8b5e879..6c7b9da 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